I have a variable with value test1/test2/test3
in my script. I want to return test1?test2?test3
. How can I make this possible??
How can I make this possible??
Thanks in advance...:)
blasteralfred
I have a variable with value test1/test2/test3
in my script. I want to return test1?test2?test3
. How can I make this possible??
How can I make this possible??
Thanks in advance...:)
blasteralfred
Share Improve this question edited Apr 5, 2011 at 17:48 Ryan 6,86613 gold badges51 silver badges68 bronze badges asked Apr 5, 2011 at 17:20 AlfredAlfred 21.4k63 gold badges174 silver badges257 bronze badges 2- try not forget that jQuery is just a javascript framework. And you shouldn't try to solve every task with it. (doxdesk./img/updates/20091116-so-large.gif) – Igor Milla Commented Apr 5, 2011 at 17:35
-
I am using it as my core and 'm a beginner.. Thats y...
:)
– Alfred Commented Apr 5, 2011 at 17:43
3 Answers
Reset to default 7You can just use the string.replace() function and use a regular expression as the first parameter specifying you want to replace the string your searching for globally.
Try this:
var str = "test1/test2/test3";
str = str.replace(/\//g,"?");
alert(str);
You simply need to use a Regular Expression with replace to match all values of "/"
Here is a link for using regular expressions
newStr = strVar.replace(/\//g,"?");
var x = 'test1/test2/test3'
x.replace(/\//g, "?");
Check example http://jsfiddle/XPHSG/