0

This is probably a very basic question, but really appreciate if you could help me with this:

I want to convert an string that contains characters like \u000d\u000a\u000d\u000 to a human readable string, however I don't want to use .Replace method since the Unicode characters might be much more than what I include the software to check and replace.

string = "Test \u000d\u000a\u000d\u000aTesting with new line. \u000d\u000a\u000d\u000aone more new line"

I receive this string as a json Object from my server.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Kourosh
  • 608
  • 2
  • 14
  • 34
  • Can you just use it to display? – MaxZoom May 12 '15 at 19:40
  • One possibility is described here: [How do convert unicode escape sequences to unicode characters in a .NET string][1] [1]: http://stackoverflow.com/questions/183907/how-do-convert-unicode-escape-sequences-to-unicode-characters-in-a-net-string – uncoder May 12 '15 at 19:48
  • thanks @uncoder I just used "Regex.Unescape(str)" wondering if this is a safe and sounds way of doing it. – Kourosh May 12 '15 at 19:57

1 Answers1

0

Do you even need that?

For example, the following code will print abc which is the actual decoded value:

var unicodeString = "\u0061\u0062\u0063";
Console.WriteLine(unicodeString);
uncoder
  • 1,818
  • 1
  • 17
  • 20
  • yes unfortunately the UI element in the software shows all the unicode characters.. – Kourosh May 12 '15 at 19:59
  • Well, there is difference between ``"\u0033"`` and ``"\\u0033"`` The first one contains an escape sequence ``\u`` which indicates a Unicode character. The second one simply starts with an escaped backslash (and that's what you're seeing in your app.) – uncoder May 12 '15 at 22:28