views:

80

answers:

2

Hi all,

I am getting a string "test+test1+asd.txt" and i want to convert it into "test test1 asd.txt"

I am trying to use function str = str.replace("/+/g"," ");

but this is not working

regards, hemant

+6  A: 
str = str.replace(/\+/g," ");
S.Mark
The `+` has special meaning in RegEx. So, you have to escape it with a backslash. That's why S.Mark's RegEx works. `\+`
EndangeredMassa
And you don't put Regex in strings in Javascript, that is the second reason your replace failed.
Doug Neiner
+1 but IMHO needs explanation, like the one from EndangeredMassa :)
Sune Rievers
A: 

+1 for S.Mark's answer if you're intent on using a regular expression, but for a single character replace you could easily use:

yourString = yourString.split("+").join(" ");
NickFitz