如何转换字符串"电子邮件地址始终使用@ sign"转换为UTF 16代码

时间:2013-09-29 07:12:50

标签: utf-16

我没有得到正确的方法将字符串“电子邮件地址始终使用@符号”转换为UTF 16代码并且还想知道它是否与ASCII代码相同?

1 个答案:

答案 0 :(得分: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相同的编码。