1

I have the following string, read from an XML attribute:

"OnTrak 4-3/4”, 6-3/4”, 8-1/4” / MPR"

In my C# application it shows up nicely formatted like this

"OnTrak 4-3/4”, 6-3/4”, 8-1/4” / MPR"

This is the form I see in the debugger, a combobox, or on this forum (if I don't indent to specify code).

What I want to do is specify the same string as a C# variable and have it show up nicely formatted when the application runs. Unfortunately, all I get is the string as I literally typed it.

I have tried to play around with converting the encoding from ASCII to UTF8 with no luck. How can I get this special character properly formatted, and where can I find a list of these symbols?

1 Answer 1

1

Those are called XML entities. Use HttpUtility.HtmlDecode to decode them back to plain text like you would like. Credit goes to C#, function to replace all html special characters with normal text characters for how to convert entities in C#

Note that converting from ASCII to UTF8 (and Unicode etc.) is called changing the character set and is usually done when specific characters are in the string. For instance if you strings contained Chinese characters you couldn't use ASCII. In this simple case you shouldn't need to convert character sets because C# strings are Unicode character set by default and XML entities are Unicode based (I believe).

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

1 Comment

Thanks, that was it. I probably wasted 2 hours on encoding, and got the answer here in 5 min.

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.