且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Flex:用逗号替换所有空格

更新时间:2022-12-11 07:57:10



  str = str.replace(/ / g ,','); 

以下是一个更好的方法,它将替换所有的空白字符串:

  str = str.replace(/ \s + / g,','); 


im new with regexp, so can i ask for some assistance

Using string.replace function what code that can replace spaces with comma

Input:The quick brown fox jumps over the lazy dog. Output:The,quick,brown,fox,jumps,over,the,lazy dog.

Thanks

Like this:

str = str.replace(/ /g, ',');

Here's a better one which will replace all strings of whitespace:

str = str.replace(/\s+/g, ',');