-2

I want to send search keywords with QueryString like google, atc... and i need a function which convert text like this

Metallica nimes concert 2009 :)

to this:

Metallica+nimes+concert+2009+%3A%29

and retrieve it

Thanks and advance

SajjadSM
  • 73
  • 9

2 Answers2

0

you need to encode the string using:

HttpUtility.UrlEncode("Metallica nimes concert 2009 :)")

you'll need to reference to System.Web

This will work on simple strings, if you want to encode more characters see: Server.UrlEncode vs. HttpUtility.UrlEncode. as Panagiotis Kanavos recommended

-1

Trying to encode a string into a URL?

Why not use system.net.webutility.urlencode

Docs here

Rock here

Loofer
  • 6,841
  • 9
  • 61
  • 102
  • Posting an answer when there are so many duplicates already doesn't help at all. It only creates adds noise and makes it *harder* to find an answer – Panagiotis Kanavos Feb 28 '18 at 17:05
  • 1
    It helps the person asking the question... it also allowed me to make the little docs here rocks here thing which pleased me. – Loofer Feb 28 '18 at 17:06
  • That's what the search button is for. In fact, are you *sure* you should use that function at all? Check the duplicate to see [why you shouldn't](https://stackoverflow.com/questions/5095351/encoding-parameters-for-a-url) – Panagiotis Kanavos Feb 28 '18 at 17:07