一个 C# 字符串最终转化为多长的字节, 取决于使用的编码

一个 C# 字符串最终转化为多长的字节, 取决于使用的编码

  string s = "china 中华人民共和国";
  int l = 0;
  byte[] b1 = System.Text.Encoding.Default.GetBytes(s);
  l = b1.Length;//20
  byte[] b2 = System.Text.Encoding.UTF8.GetBytes(s);
  l = b2.Length;//27
  byte[] b3 = System.Text.Encoding.Unicode.GetBytes(s);
  l = b2.Length;//26

转自:http://topic.csdn.net/u/20090520/23/c904b6b0-e1e8-4181-a2bd-045f5bf714cc.html

 

你可能感兴趣的:(字符串)