2

H, I have this string that I got from a htm file

String s = "%u05d9%u05e8%u05d5%u05e9%u05dc%u05d9%u05dd"

It is in UTF8 code value Hebrew characters and I want to convert it to a real string that I can write to a file and have meaning (not just the code value of the char set).

I tried to do this but it does not work -

byte[] bytes = Encoding.UTF8.GetBytes(s);
addr = Encoding.UTF8.GetString(bytes);
Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
Yoav Amir
  • 23
  • 1
  • 3
  • 2
    @huMptyduMpty: It may be a duplicate, but certainly not of that question. The one you linked is Base64 encoded, as you can see from answers provided to both this question and the one you linked, the solutions are completely different.... so they must be different questions – musefan Dec 02 '14 at 14:14

2 Answers2

5

The original string might have been UTF-8 encoded, but this is irrelevant because what you have right now is an URL encoded string. You can decode it using HttpUtility.UrlDecode:

System.Web.HttpUtility.UrlDecode("%u05d9%u05e8%u05d5%u05e9%u05dc%u05d9%u05dd")

returns ירושלים

Dirk
  • 10,668
  • 2
  • 35
  • 49
  • I tried to use System.Web but I don't have HttpUtility at all. In the MSDN it says that - "To encode or decode values outside of a web application, use the WebUtility class." So I tried - System.Net.WebUtility.UrlDecode(s); Like maruthu chandrasekaran suggest but still it does not do any thing. It returns me my original string - %u05d9%u05e8%u05d5%u05e9%u05dc%u05d9%u05dd – Yoav Amir Dec 03 '14 at 06:16
  • You are right, WebUtility.UrlDecode apparently works differently than HttpUtility.UrlDecode. You can still use HttpUtility outside of a web application. All you have to do is reference System.Web.dll. – Dirk Dec 03 '14 at 07:08
  • I add the reference and it works! Thanks! :) – Yoav Amir Dec 03 '14 at 08:07
0

try

System.Net.WebUtility.UrlDecode(s);
  • I tried - System.Net.WebUtility.UrlDecode(s); but still it does not do any thing. It returns me my original string - %u05d9%u05e8%u05d5%u05e9%u05dc%u05d9%u05dd – Yoav Amir Dec 03 '14 at 06:18