코드 세그먼트: ASCII to Unicode

2914 단어 unicode
   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: }

좋은 웹페이지 즐겨찾기