0

I get the following Unicode as a parameter from a URL which is connected to my webservice:

%u0633%u0644%u0627%u0645  

This code is representation of a 4-letter Persian word and I want to use it in its true form (save to DB/write to log/etc) and I want to know how should I cast it using C# code.

Sina Hoseinkhani
  • 318
  • 4
  • 15
  • 1
    Possible duplicate of [Unicode-to-string conversion in C#](https://stackoverflow.com/questions/4184190/unicode-to-string-conversion-in-c-sharp) – RH6 Oct 24 '17 at 14:16
  • That's not a Unicode representation.It's a **URL** encoding – Panagiotis Kanavos Oct 24 '17 at 14:38
  • @RH6 that link doesn't apply and the title is (severly) misleading anyway. Strings in C# are Unicode. You *can't* have ASCII strings even if you wanted to. That's why there's no accepted answer. Whatever the issue was in this case, it wasn't Unicode. – Panagiotis Kanavos Oct 24 '17 at 14:39
  • @PanagiotisKanavos - would "representation of unicode characters in URL encoding" be better phrasing? – Corak Oct 24 '17 at 14:42
  • @Corak everyone uses the term `URL Encoding` or [percent encoding](https://en.wikipedia.org/wiki/Percent-encoding). You can find the appropriate methods immediatelly, as you did, if you know the name. Thinking of this as "Unicode" results in a lot of wasted time searching for inappropriate solutions – Panagiotis Kanavos Oct 24 '17 at 14:43
  • @PanagiotisKanavos - agreed. The biggest hurdle is knowing the term. OP didn't (apparently), but knew it had something to do with unicode and made it clear (although just in text) that he/she is working with part of a URL. So I'd see value for people not knowing `URL encoding` directly but would be looking for `unicode + url`, *if* `URL` would be part of the title. – Corak Oct 24 '17 at 14:54
  • Yes I didn't know the correct term for it and spent alot of time searching and trying. I edited the title to also reflect both URL encoding and percent encoding to help clarify it for people. – Sina Hoseinkhani Oct 24 '17 at 15:34

1 Answers1

0

It's (part of) a URL, so System.Web.HttpUtility.UrlDecode should do the trick.

string value = System.Web.HttpUtility.UrlDecode("%u0633%u0644%u0627%u0645");
// value is: سلام
Corak
  • 2,688
  • 2
  • 21
  • 26