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


  • BK: 大於和小於在今日更廣泛地使用於標籤上,故在此補充該英文用法: : angle bracket []: square bracket
  • luh1688: 非常實用且謝謝!~
  • asd: 好的,不過很久沒修改了,不知道能不能動 寄到您的yahoo信箱
  • LIANG: nice post, thank you
  • Justmaker: 您好,請問可以跟你要source嗎?我最近有在看股票,想要enhance您的小工具,不知是否可以開放?

Category