Tuesday, July 19, 2011

Convert UTF-8 to Unicode extension

The code:

public static string UTF8ToUnicode(this string input)

{

    return Encoding.Unicode.GetString(

                        Encoding.Convert(Encoding.UTF8,

                                            Encoding.Unicode,  

                                            Encoding.UTF8.GetBytes(

                                                        input)));

}

 

Example:

 

string txt ="Hello, World!";

txt.UTF8ToUnicode();

2 comments:

  1. I am not sure this works well. You should enhance your example with more exotic cahracters like é页말...

    ReplyDelete
  2. Excellent, Thank you so much. It helped me a lot

    ReplyDelete