Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting space to "+" using C#

I want to convert a string to an url and, instead of a space, it needs a "+" between the keywords.

For instance:

"Hello I am"

to:

"Hello+I+am"

How should i do this?

like image 872
klopske Avatar asked Nov 28 '22 11:11

klopske


2 Answers

For URLs, I strongly suggest to use Server.UrlEncode (in ASP.NET) or Uri.EscapeUriString (everywhere else) instead of String.Replace.

like image 150
Alon Gubkin Avatar answered Dec 14 '22 23:12

Alon Gubkin


String input = "Hello I am";
string output = input.Replace(" ", "+");
like image 44
Katalonis Avatar answered Dec 14 '22 23:12

Katalonis