0

For example: mystr="\"http:\\/\\/somedomain.com\"";

i want to convert this string to "http://somedomain.com";

HttpUtility.HtmlDecode and HttpUtility.UrlDecode dont work

how can convert this?

2
  • 1
    Sample string represents ( "http:\/\/somedomain.com" ) Commented Sep 22, 2012 at 5:20
  • 1
    ebattu, are the double escapes after http correct? Commented Sep 22, 2012 at 8:20

1 Answer 1

5

This is because you need to escape the "\" and the quotes (") character in C#. There is no Encoding / Decoding to do. If you want to get rid of the confusing backslashes add a @ before your string

myStr = @"http://www.google.com"

Nevertheless, your string looks weird so you will need to get the text inside the quotes and then remove those weirdly placed "\" in the http:// part.

Sign up to request clarification or add additional context in comments.

6 Comments

this is dynamic string. not static
When i parsing json using result=jsonValue.Parse(text).asDynamic(). After result.domain` contains literal string. I need to convert result.domain
jike @jtimperley mentioned your encoding looks funky. There might be a way to get the value you need more easily. if not, you need to strip the quotes. Then just remove all "\" (considering it's a URI they shouldn't be there anyways...).
When i debugging result.domain error: cannot debug dynamic value. Next time string mystr=result.domain.ToString(); Then watch mystr in debugger, looks like "\"http:\\/\\/somedomain.com\""
I am not that much in c# but this link may help you. @ebattulga
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.