10

I have a string from UTF8 and want to convert that to Unicode (UTF16). Please help.

6
  • 6
    I suggest you read this article first by Joel Splosky joelonsoftware.com/articles/Unicode.html Commented May 11, 2011 at 10:16
  • Hi @Fraisal, isn't UTF8 an implementation of Unicode? en.wikipedia.org/wiki/Unicode Commented May 11, 2011 at 10:16
  • 1
    UTF8 is Unicode. Do you mean that you want to convert it to UTF-16, which is teh Unicode encoding used by .NET? Commented May 11, 2011 at 10:16
  • 1
    All strings in C# are in Unicode. Be more specific in string source and target. Commented May 11, 2011 at 10:17
  • @jalf, yes i want to convert it to utf16 Commented May 11, 2011 at 10:18

2 Answers 2

17

If you have a file and you know that encoding of the file is UTF8 you can use StreamReader to read the file as if it is encoded in UTF8.
Regarding conversion from UTF8 to Unicode, you are comparing 2 different things. Check the link in my comment to your question.
System.Text.UTF8Encoding is UTF8 System.Text.UnicodeEncoding is UTF16. Check this link for conversion. You would be using Encoding.Convert()

Sign up to request clarification or add additional context in comments.

1 Comment

System.Text.UnicodeEncoding is the thing I was looking for the past few hours.
6

Use System.Text.Encoding.UTF8.GetString().

Pass in your UTF-8 encoded text, as a byte array. The function returns a standard .net string which is encoded in UTF-16.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.