最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - replace specific characters from variable - jquery - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 7

You 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/

发布评论

评论列表(0)

  1. 暂无评论