我没有得到正确的方法将字符串“电子邮件地址始终使用@符号”转换为 UTF 16 代码并且还想知道它是否与 ASCII 代码相同?
问问题
542 次
1 回答
0
使用命令行。
如果你不关心字节顺序,你会得到一个 BOM:
$ echo "Email addresses always use the @ sign" | iconv -t utf-16 | hexdump
0000000 fe ff 00 45 00 6d 00 61 00 69 00 6c 00 20 00 61
0000010 00 64 00 64 00 72 00 65 00 73 00 73 00 65 00 73
0000020 00 20 00 61 00 6c 00 77 00 61 00 79 00 73 00 20
0000030 00 75 00 73 00 65 00 20 00 74 00 68 00 65 00 20
0000040 00 40 00 20 00 73 00 69 00 67 00 6e 00 0a
000004e
这是大端:
$ echo "Email addresses always use the @ sign" | iconv -t utf-16be | hexdump
0000000 00 45 00 6d 00 61 00 69 00 6c 00 20 00 61 00 64
0000010 00 64 00 72 00 65 00 73 00 73 00 65 00 73 00 20
0000020 00 61 00 6c 00 77 00 61 00 79 00 73 00 20 00 75
0000030 00 73 00 65 00 20 00 74 00 68 00 65 00 20 00 40
0000040 00 20 00 73 00 69 00 67 00 6e 00 0a
000004c
还有小端:
$ echo "Email addresses always use the @ sign" | iconv -t utf-16le | hexdump
0000000 45 00 6d 00 61 00 69 00 6c 00 20 00 61 00 64 00
0000010 64 00 72 00 65 00 73 00 73 00 65 00 73 00 20 00
0000020 61 00 6c 00 77 00 61 00 79 00 73 00 20 00 75 00
0000030 73 00 65 00 20 00 74 00 68 00 65 00 20 00 40 00
0000040 20 00 73 00 69 00 67 00 6e 00 0a 00
000004c
您应该在最后删除换行符。
哦,不,UTF-16 绝对不是与 ASCII 相同的编码。
于 2013-09-29T07:21:12.777 回答