Flex:用逗号替换所有空格 [英] Flex: replace all spaces with comma

查看:142
本文介绍了Flex:用逗号替换所有空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的正则表达式,所以我可以要求一些援助

使用string.replace函数什么代码可以用逗号代替空格

输入:快速的棕色狐狸跳过懒惰的狗。
输出:,快速,棕色,狐狸,跳跃,在,懒狗。

谢谢

解决方案



  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, ',');

这篇关于Flex:用逗号替换所有空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆