2

is it possible to convert a string like "\u00e8" (Got it by reading a WebRequestResponse with Streamreader) to it's unicode char(è)? Tried many things with Encoding, but nothing works.

  • 1
    Please show us what you've tried, so we don't offer solutions that have already not worked for you. –  Sep 21 '16 at 15:06
  • 1
    Can you show how the code, best done in an [mcve], you *tried* to set the encoding? – rene Sep 21 '16 at 15:07
  • 1
    Presumably this text is part of something else - is it JSON? If so, just use a JSON parser... – Jon Skeet Sep 21 '16 at 15:08
  • I've tried using every available Encoding at 'new StreamReader(dataStream, Encoding.)' Yes it is JSon, also tried HttpUtility.JavaScriptStringEncode(Source), but it also doesn't do what i want –  Sep 21 '16 at 15:15

1 Answers1

2

You can use Regex.Unescape(), which unescapes any escape sequences that are valid for a Regex (including \uXXXX). Note that it also unescapes other sequences like \t, \n, and \[.

Mark Cidade
  • 98,437
  • 31
  • 224
  • 236
  • Thank you very much, it worked! –  Sep 21 '16 at 15:16
  • 1
    Two downvotes and absolutely no explanation. Can someone clue me in here? I also found the following: http://stackoverflow.com/a/31362213/2524589 They suggest using System.Uri.UnescapeDataString(string) – KSib Sep 21 '16 at 15:18