我使用以下命令在空白处拆分字符串
myString.split("\\s+");
我如何为单个空格提供异常(exception)。即除单个空格外的空格
最佳答案
像这样:
myString.split("\\s{2,}");
或者像这样,
myString.split(" \\s+"); // notice the blank at the beginning.
这取决于你真正想要的是什么,通过阅读问题并不清楚。
您可以在 Pattern 中检查量词语法类。
关于java - 在除单个空格外的空格上拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17525765/