Click here to Skip to main content
16,013,548 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi!

I have a string, witch contains many spaces, I need to change the space characters to %20.

THX for any help!
Posted
Comments
Sergey Alexandrovich Kryukov 20-Feb-14 12:13pm    
Why do you think it should be done only with space characters? I bet what you need is not what you are asking about.
Please see my answer.
—SA

In general case, you just use string.Replace:
http://msdn.microsoft.com/en-us/library/czx8s9ts(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/fk49wtc1(v=vs.110).aspx[^].

But I am nearly sure that what you really need is not what you are asking for. Most likely, you need to encode not only spaces, but everything which is not allowed in URL. Please see:
http://en.wikipedia.org/wiki/Percent-encoding[^].

This is how: http://msdn.microsoft.com/en-us/library/zttxte6w%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
There are loads of ways, but the simplest might be:
string output = input.Replace(" ", "%20");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900