0

I wanna know how I could convert an appearance of the hex escape sequence "\uxxxx" (where x is a hex digit) to plaintext, i.e. "\\uxxxx" so I can print it somewhere. I tried

string convertedString = System.Text.RegularExpressions.Regex.Unescape("\u1234");

but the string gets some strange value. Same with Escape. Regex.Unescape does not "convert any escaped characters in the input string" enter image description here I tried something like

convertedString = ("\u1234").Replace("\u", "\\u");

but compiler tells me "Unrecognized escape sequence" because he expects 4 more digits.

"Unrecognized escape sequence"

Also not working:

string convertedString = ("\u1234").Replace(@"\u", @"\\u");

enter image description here

Hope somebody can help me. :)

duesterdust
  • 87
  • 1
  • 7
  • 1
    `Replace("\\u", "\\\\u")`, or `Replace(@"\u", @"\\u")`. You were also looking for `Regex.Escape`, not `Regex.Unescape` – canton7 Jan 23 '20 at 11:37
  • Tried it but nothing works. – duesterdust Jan 23 '20 at 11:57
  • Ah I see what you're doing. When you write `"\u1234"`, the compiler turns that into the `ሴ` character. When your code runs, it's looking at the string `"ሴ"`, and not the string `"\1234"`. – canton7 Jan 23 '20 at 12:03
  • 1
    Does this answer your question? https://stackoverflow.com/questions/1615559/convert-a-unicode-string-to-an-escaped-ascii-string – canton7 Jan 23 '20 at 12:03

0 Answers0