开发者

Replace comma by double quote in javascript

How to replace comma by double quote in javascript? For example: "c,C#,开发者_如何学编程JavaScript" should be like "C","C#","JavaScript"


str = '"c,C#,JavaScript"';
str = str.split(',').join('","');

That would result in "c","C#","JavaScript"


var original = '"c,C#,JavaScript"';

var quoted = original.replace(/,/g, '","');    // "c","C#","JavaScript"


Just to toss it in there, you could also .split() and .join(), like this:

var oldString = '"c,C#,JavaScript"';
var newString = oldString.split(',').join('","');

You can test it here.


You can do this:

str = "c,C#,JavaScript";
str = str.replace(/,/g, '"');

Result:

c"C#"JavaScript
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜