Reputation: 1628
I have a string looking like: some+thing+-+More
How do i replace the + sign?
I have tried the following without success:
temps = "some+thing+-+More";
temps = temps.replace("/+" /g, "blank");
temps = temps.replace("+" /g, "blank");
temps = temps.replace(/+/g, "blank");
Upvotes: 0
Views: 102
Reputation: 1628
Thanks Jonathan.
I took a different approach: I figure out the Hex number for + sign was 2B So....
temps = temps = temps.replace(/\x2B/g, "blank");
also did the trick!
Upvotes: 0
Reputation: 866
"+ + + +".replace(/\+/g, "blank")
This results:
"blank blank blank blank"
You should use the escape char:
temps = temps.replace(/\+/g, "blank");
Upvotes: 0
Reputation: 57167
You need to escape the plus sign with a backslash, like so:
var temps ="some+thing+-+More";
temps = temps.replace(/\+/g, "blank");
Upvotes: 8