EvoTalk

03 二月, 2010

C# to convert from utf-8 bytes to string and back.

Posted by: asd In: C++| Code Snippet| 程式設計 ()

CODE:
  1. System.Text.Encoding utf_8 = System.Text.Encoding.UTF8;
  2.  
  3. // This is our Unicode string:
  4. string s_unicode = "abcéabc";
  5.  
  6. // Convert a string to utf-8 bytes.
  7. byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes(s_unicode);
  8.  
  9. // Convert utf-8 bytes to a string.
  10. string s_unicode2 = System.Text.Encoding.UTF8.GetString(utf8Bytes);
  11.  
  12. MessageBox.Show(s_unicode2);

reference : C# to convert from utf-8 bytes to string and back

Most Commented Posts



No Responses to "C# to convert from utf-8 bytes to string and back."

Comment Form