1: private string ConvertAsciiToUnicode(string theAsciiString)
   2:  {
   3:     // Create two different encodings.
   4:     Encoding aAsciiEncoding = Encoding.ASCII;
   5:     Encoding aUnicodeEncoding = Encoding.Unicode;
   6:  
   7:     // Convert the string into a byte[].
   8:     byte[] aAsciiBytes = aAsciiEncoding.GetBytes(theAsciiString);
   9:  
  10:     // Perform the conversion from one encoding to the other.
  11:     byte[] aUnicodeBytes = Encoding.Convert(aAsciiEncoding, aUnicodeEncoding,
  12:     aAsciiBytes);
  13:  
  14:     // Convert the new byte[] into a char[] and then into a string.
  15:     char[] aUnicodeChars = new
  16:     char[aUnicodeEncoding.GetCharCount(aUnicodeBytes, 0, aUnicodeBytes.Length)];
  17:     aUnicodeEncoding.GetChars(aUnicodeBytes, 0, aUnicodeBytes.Length,
  18:     aUnicodeChars, 0);
  19:     string aUnicodeString = new string(aUnicodeChars);
  20:  
  21:     return aUnicodeString;
  22: }

相关文章:

  • 2022-01-31
  • 2022-12-23
  • 2021-11-16
  • 2021-07-07
  • 2022-02-17
  • 2022-01-28
  • 2021-12-13
猜你喜欢
  • 2021-06-08
  • 2021-06-15
  • 2021-08-25
  • 2022-12-23
  • 2021-09-26
  • 2022-02-25
  • 2022-02-18
相关资源
相似解决方案