Flex:用逗号替换所有空格 [英] Flex: replace all spaces with comma
本文介绍了Flex:用逗号替换所有空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 regexp 的新手,所以我可以寻求一些帮助
im new with regexp, so can i ask for some assistance
用string.replace函数用什么代码可以用逗号代替空格
Using string.replace function what code that can replace spaces with comma
输入:敏捷的棕色狐狸跳过懒狗.输出:The,quick,brown,fox,jumps,over,the,lazy dog.
Input:The quick brown fox jumps over the lazy dog. Output:The,quick,brown,fox,jumps,over,the,lazy dog.
谢谢
推荐答案
像这样:
str = str.replace(/ /g, ',');
这是一个更好的替换所有空格字符串的方法:
Here's a better one which will replace all strings of whitespace:
str = str.replace(/\s+/g, ',');
这篇关于Flex:用逗号替换所有空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文