Replace all commas in a string
This question already has an answer here:
You can use RegExp with g
flag.
var mystring = "this,is,a,test"
mystring.replace(/,/g , "newchar");
DEMO: http://jsfiddle.net/d4N9s/
只是为了好玩:
var mystring = "this,is,a,test"
var newchar = '|'
mystring = mystring.split(',').join(newchar);
var mystring = "this,is,a,test"
mystring.replace(/,/g, "newchar");
Use the global( g
) flag
Simple DEMO
链接地址: http://www.djcxy.com/p/16832.html下一篇: 替换字符串中的所有逗号