使用 JavaScript 分割单词,但会跳过“\”之前的一些单词
我有一个字符串:
"a","b","c"
我可以将这些单词拆分为:
a b c
使用 Javascript,但是怎么样:
"a,","b\"","c\,\""
我如何得到:
a, b" c,"
I have a string:
"a","b","c"
and I can split those words to:
a b c
using Javascript, but how about:
"a,","b\"","c\,\""
How do I get:
a, b" c,"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
仍然不确定这是否是一根绳子?但如果它是...并且这是您想要操纵的唯一实例,您可以使用这种超级复杂的方式...
示例: http://jsfiddle.net/jasongennaro/ceVG7/1/
Still not sure if this is one string? But if it is... and this is the only instance of it that you want manipulated, you could use this super convoluted way....
Example: http://jsfiddle.net/jasongennaro/ceVG7/1/
\
(使用replace()
)\
in each resultant string, after the split (usingreplace()
)您不能将“a”、“b”、“c”定义为一个字符串。如果你有一个字符串,则
replace()方法会搜索子字符串(或正则表达式)和字符串之间的匹配项,并用新的子字符串替换匹配的子字符串。
split() 方法用于将字符串拆分为子字符串数组,并返回新数组。
或者
var myString = "abc,efg";
You cannot define "a","b","c" as one string. If you have a string then,
The replace() method searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring.
The split() method is used to split a string into an array of substrings, and returns the new array.
or
var myString = "abc,efg";
怎么样:
如果输出不是 HTML,则可以将
替换为
\n
What about this:
that gives:
<br/>
can be replaced by\n
if the output is not HTML