我该如何拆分这个字符串? [英] How can I split this string ?
本文介绍了我该如何拆分这个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
他是一个非常好的男孩,不是吗?
答案的格式为,
10
他
是
a
非常
非常好
好
男孩
isn
t
他
我尝试过:
He is a very very good boy, isn't he?
The answer would be in the format of,
10
He
is
a
very
very
good
boy
isn
t
he
What I have tried:
String [] arrOfStr = str.split(" ");
推荐答案
因为你不想要逗号,我想最好匹配单词而不是而不是分隔空格。
我会使用RegEx,如:\ w +
只是一些有趣的链接来帮助构建和调试RegEx 。
以下是RegEx文档的链接:
perlre - perldoc.perl .org [ ^ ]
以下是帮助构建RegEx并调试它们的工具的链接:
.NET Regex Tester - Regex Storm [ ^ ]
Expresso正则表达式工具 [ ^ ]
RegExr:Learn,Build,&测试RegEx [ ^ ]
在线正则表达式测试器和调试器:PHP,PCRE,Python,Golang和JavaScript [ ^ ]
这个显示RegEx是一个很好的图表,它非常有助于理解RegEx的作用:
Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]
这个网站也在一个漂亮的图表中显示正则表达式,但无法测试与RegEx匹配的内容:
Regexper [ ^ ]
Since you don't want commas, I guess it is preferable to match words rather than split on spaces.
I would use a RegEx like: \w+
Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx:
Regexper[^]
查看我过去的回答:如何将文本文件转换为XML [ ^ ]
Check my past answer: How do I convert a text file into XML[^]
这篇关于我该如何拆分这个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文