<分区>
Possible Duplicate:
How to split a String by space
我在解析文本文件时需要帮助。 文本文件包含如下数据
This is different type of file.
Can not split it using ' '(white space)
我的问题是单词之间的空格不相似。有时是单个空格,有时是多个空格。
我需要以只得到单词而不是空格的方式拆分字符串。
<分区>
Possible Duplicate:
How to split a String by space
我在解析文本文件时需要帮助。 文本文件包含如下数据
This is different type of file.
Can not split it using ' '(white space)
我的问题是单词之间的空格不相似。有时是单个空格,有时是多个空格。
我需要以只得到单词而不是空格的方式拆分字符串。
最佳答案
str.split("\\s+")
会起作用。正则表达式末尾的 +
会将多个空格视为一个空格。它返回一个字符串数组 (String[]
),没有任何 ""
结果。
关于java - 在java中的多个空格上拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13081527/