英文:
Trying to print a big string in go
问题
我正在尝试打印保存在数据库中的Java安全整数,这是一个示例:
我有以下代码:
salt := "fqm0vp02103inkmvb18cgqbv0s9v7o43o12hj0nhj9jqit8nh327re7iup2imdtedepch8alam8340u4rcd923g9nuubh3a4jbdonr67phej9fp9oitudnp3dabi09nr"
fmt.Printf(salt)
这是我在Go中得到的结果,但我需要将字符串与数据库中的内容保持一致:
66716d3076703032313033696e6b6d76623138636771627630733976376f34336f3132686a306e686a396a716974386e6833323772653769757032696d647465646570636838616c616d38333430753472636439323367396e757562683361346a62646f6e7236377068656a396670396f697475646e70336461626930396e72
请注意,这是一个十六进制字符串。
英文:
I'm trying to print a java secure integer saved in a database, this is an example:
i have this:
<!-- language: go -->
salt := "fqm0vp02103inkmvb18cgqbv0s9v7o43o12hj0nhj9jqit8nh327re7iup2imdtedepch8alam8340u4rcd923g9nuubh3a4jbdonr67phej9fp9oitudnp3dabi09nr"
fmt.Printf(salt)
this is what i got in go, but i need the string as it is in the database:
66716d3076703032313033696e6b6d76623138636771627630733976376f34336f3132686a306e686a396a716974386e6833323772653769757032696d647465646570636838616c616d38333430753472636439323367396e757562683361346a62646f6e7236377068656a396670396f697475646e70336461626930396e72
答案1
得分: 1
如评论中所提到的,您只需要对字符串进行十六进制编码,然后就可以匹配了:
package main
import (
"fmt"
"encoding/hex"
)
func main() {
salt := "fqm0vp02103inkmvb18cgqbv0s9v7o43o12hj0nhj9jqit8nh327re7iup2imdtedepch8alam8340u4rcd923g9nuubh3a4jbdonr67phej9fp9oitudnp3dabi09nr"
fmt.Println(hex.EncodeToString([]byte(salt)))
}
英文:
As mentioned in a comment, you just need to hex encode your string and will will match:
https://play.golang.org/p/p4XLYd0smZ
package main
import (
"fmt"
"encoding/hex"
)
func main() {
salt := "fqm0vp02103inkmvb18cgqbv0s9v7o43o12hj0nhj9jqit8nh327re7iup2imdtedepch8alam8340u4rcd923g9nuubh3a4jbdonr67phej9fp9oitudnp3dabi09nr"
fmt.Println(hex.EncodeToString([]byte(salt)))
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论