opensas
opensas

Reputation: 63585

Convert a string to a utf8 string

I'm trying to convert a string like

<Root>á</Root>

To it's UTF string representation, like this

<Root>á</Root>

(Taken from this page: http://www.cafewebmaster.com/online_tools/utf8_encode)

But when I issue Encoding.UTF8.GetBytes(str) I get an array of utf bytes.

How can I convert those bytes to the string representation I'm after?

--

Thanks for pointing that there is no string representation of an utf8 string.

Just to clarify my needs, I have to execute something like this in sql 2008:

xmlAuditoria_Alta 
'
<Out>utf8 char: á</Out>
'

This is the only way I found so far to have this stored precedure correctly save the value

utf8 char: á

That's why I'm trying to convert from á to á

Perhaps there's a more correct way to do it

Upvotes: 0

Views: 635

Answers (1)

David Heffernan
David Heffernan

Reputation: 613451

Your question is based on an erroneous premise.

<Root>á</Root>

is not the UTF-8 representation of your string. In fact that string is the UTF-8 bytes re-interpreted in some other single-byte 8 bit character set.

If you want to convert a C# string to UTF-8 then you do indeed write:

Encoding.UTF8.GetBytes(str)

Upvotes: 8

Related Questions