我试图接受String一个输入,用空格字符分割它以便将单词存储在数组中,然后使用这些单词与其他单词进行比较.问题是我希望在拆分期间忽略句点,因为它们被比较的单词将永远不会包含句点.
例如:
String testString = "This. is. a. test. string.";
String[] test = testString.split(" ");
for (int i = 0; i < test.length; i++) {
System.out.println(test[i]);
}
Run Code Online (Sandbox Code Playgroud)
这将打印出来:
This.
is.
a.
test.
string.
Run Code Online (Sandbox Code Playgroud)
相反,我希望打印出来:
This
is
a
test
string
Run Code Online (Sandbox Code Playgroud)
如何忽略拆分期间的时间段?