• 0

C# replace elements of string with hex (html)


Question

This may be simple, and I may be just being an idiot and doing the wrong search term.

What I want is to take a Uri, and replace certain elements with it's hex counterpart, for a query string.

I use String.Replace() and this is getting tedious.

Example, myQueryString=c# .net html parser becomes myQueryString=c%23+.net+html+parser

I'd like to be able to do the reverse as well.

Any ideas other than a string.Replace for every element that might show up in one of these?

EDIT: I guess I could create an array of characters that don't need converted A-Z, a-z, etc.. then loop through the string and only replace what does need it. This seems stupid though.

Edited by rev23dev
Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

eh, screw it. that will work.

thanks!

anything that does html string markup?

i.e. replace   with space, & with &?

Thanks

Link to comment
Share on other sites

  • 0

Generally it's trial and error with Server.HtmlEncode, Server.UrlEncode and HttpUtility.UrlEncode. I can never remember which does what and they're all subtly different.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.