尝试在Go语言中打印一个大字符串。

huangapple go评论89阅读模式
英文:

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 := &quot;fqm0vp02103inkmvb18cgqbv0s9v7o43o12hj0nhj9jqit8nh327re7iup2imdtedepch8alam8340u4rcd923g9nuubh3a4jbdonr67phej9fp9oitudnp3dabi09nr&quot;
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 (
    &quot;fmt&quot;
    &quot;encoding/hex&quot;
)

func main() {
    salt := &quot;fqm0vp02103inkmvb18cgqbv0s9v7o43o12hj0nhj9jqit8nh327re7iup2imdtedepch8alam8340u4rcd923g9nuubh3a4jbdonr67phej9fp9oitudnp3dabi09nr&quot;
    fmt.Println(hex.EncodeToString([]byte(salt)))
}

huangapple
  • 本文由 发表于 2017年1月12日 01:40:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/41597321.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定