C#ASCII或Unicode [英] C# ASCII or Unicode
问题描述
执行以下操作:
byte[] byteData = Encoding.ASCII.GetBytes(data);
这是因为这些代码示例很旧吗?不应该是:
byte[] byteData = Encoding.Unicode.GetBytes(data);
感谢您的输入!
这取决于-您希望结果采用ASCII还是UTF-16?当您想要彼此时,每个都是错误的.
如果您正在谈论某种网络协议,则必须找出该协议需要的字符编码.使用错误的编码,就会发生坏事.
当然ASCII有很多限制-它是非常基于英语的(仅拉丁字符,没有重音),但是对于某些协议是正确的.其他人可能会使用UTF-16(Encoding.Unicode),UTF-8或其他编码...或者让您自己在协议中指定编码.
hi im a beginner in programming and network development. i have a question regarding ASCII and Unicode encoding.
in msdn and other web examples do the following:
byte[] byteData = Encoding.ASCII.GetBytes(data);
is this because these code samples are old? shouldn't it be:
byte[] byteData = Encoding.Unicode.GetBytes(data);
thanks for your input!
It depends - do you want the result to be in ASCII or UTF-16? Each is wrong when you want the other.
If you're talking some network protocol, you must find out which character encoding is expected by the protocol. Use the wrong encoding, and Bad Things Will Happen.
Of course ASCII has massive restrictions - it's very English-based (Latin characters only, no accents) but it's correct for some protocols. Others may use UTF-16 (Encoding.Unicode), UTF-8 or other encodings... or they'll let you specify the encoding yourself within the protocol.
这篇关于C#ASCII或Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!