【发布时间】:2015-12-12 19:14:39
【问题描述】:
我怎样才能分割一个句子用空格和同时绘制的内容
例如
String Sentence="Please , tell me about : job, hobby";
String[] words = Sentence.split(" ");',' ':' ' ' 拆分,
如何解决多次拆分?
【问题讨论】:
我怎样才能分割一个句子用空格和同时绘制的内容
例如
String Sentence="Please , tell me about : job, hobby";
String[] words = Sentence.split(" ");',' ':' ' ' 拆分,
如何解决多次拆分?
【问题讨论】:
您可以使用非单词命令和量词:
String sentence="Please , tell me about : job, hobby";
System.out.println(Arrays.toString(sentence.split("\\W+")));
输出
[Please, tell, me, about, job, hobby]
您还可以使用具有所需特定标记的字符类:
System.out.println(Arrays.toString(sentence.split("[,: ]+")));
(相同的输出)
文档
Here.
【讨论】: