Equivalent of php's chr in golang

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

Equivalent of php's chr in golang

问题

我正在尝试将一个函数从PHP转换为Golang。这个函数的作用是使用chr、ord和base64_encode对一些字符串进行编码。PHP生成一个类似于122|234|135|138|179|19|190|183|80|156|4|159|195|213|86|241|140|7|112|23|61|182|37|91|185|26|203|185|206|206|183的序列整数。其中一些数字大于127,而ASCII最大的数字是127。现在的问题是:PHP的chr(206)与Golang的string(rune(206))不等价。请帮助我,谢谢。

英文:

i am try to change a fuction from php to golang . the function job is use chr,ord,base4_encode to encode some string。php generate a serial int number, like 122|234|135|138|179|19|190|183|80|156|4|159|195|213|86|241|140|7|112|23|61|182|37|91|185|26|203|185|206|206|183,
some number biger than 127,the ascii bigest number is 127.
now, the probrem is:
php's chr(206) is not equivalent golang's string(rune(206))

please help me,thx

答案1

得分: 1

PHP和Go的结果不同,因为每个语言的文档都说明了,PHP的chr返回其参数的ASCII字符,而Go的rune则使用UTF-8编码。在127以下,ASCII和UTF-8是相同的,但在127以上,它们是不同的。

英文:

The results in PHP and Go are different because, as the documentation for each states, PHP's chr returns the ASCII character for its argument, whereas Go's rune uses UTF-8. Below 127, ASCII and UTF-8 are the same, but above that, they differ.

huangapple
  • 本文由 发表于 2017年6月28日 21:44:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/44804276.html
匿名

发表评论

匿名网友

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

确定