-1

I have this string that was UTF8 encoded from PHP.

Encoded value : tr\u008fs

How do I get the original value back using C#?

The original value should be très.

thomasrutter
  • 114,488
  • 30
  • 148
  • 167
duyn9uyen
  • 9,585
  • 12
  • 43
  • 54
  • There is some code to do this conversion [here.](http://stackoverflow.com/questions/1615559/convert-a-unicode-string-to-an-escaped-ascii-string) – Jon Jan 30 '17 at 16:51
  • 2
    Is that encoded value definitely correct? I would expect è to be \u00e8 rather than \u008f And Damjan's solution works with the former but not the latter. – Jon Jan 30 '17 at 17:07
  • Jon is right. The initial character should be \u00e8 instead of \u008f (as per: https://unicode-table.com/en/#00E8) – Damjan Tomic Jan 30 '17 at 17:22
  • Possible duplicate http://stackoverflow.com/questions/12144568/storing-a-string-as-utf8-in-c-sharp – activ8 Jan 30 '17 at 17:38
  • @Jon, You are right. I didn't see this. This is probably the issue. Thanks for pointing this out. I need to investigate. – duyn9uyen Jan 30 '17 at 18:10
  • The code you've shown is an escaped Unicode code point, *not* UTF-8. If anything you are converting *back* to UTF-8. – thomasrutter Jan 31 '17 at 01:06

1 Answers1

0

Try this:

Encoding encoding = new UTF8Encoding();
string s = "tr\u008fs";            
string value = encoding.GetString(encoding.GetBytes(s));
Damjan Tomic
  • 390
  • 2
  • 11