Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1155

c# - How do I convert this UTF16 string to UTF8?

$
0
0

I have situation where I am receiving a string that represents the data read from a UTF16 file. (i don't have control over the incoming data). The string looks like:

&#FF;&#FE;Y�F�T�8�1�1�...

The same file stored as UTF8 comes in as:

YFT811  {1500}02        P *{1510}...

Is there a way to convert the incoming UTf16 string to the normal ASCII characters?

I tried:

        // Get UTF16 bytes and convert UTF16 bytes to UTF8 bytes        byte[] utf16Bytes = Encoding.Unicode.GetBytes(utf16String);        byte[] utf8Bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, utf16Bytes);        // Return UTF8 bytes as ANSI string        return Encoding.Default.GetString(utf8Bytes);

But it just returned the same characters which makes sense, but not sure how to proceed.


Viewing all articles
Browse latest Browse all 1155

Latest Images

Trending Articles



Latest Images