for (String retval: text.split("\\!\\.\\?"))
{
}
String text1 = "she said i know that she likes english food!";
试图在处分割文本! 。 ?但是以上方法似乎不起作用,无法继续使用!
输出:
预处理生成了
[she, said, i, know, that, she, likes, english, food!]
,但预期结果为[she, said, i, know, that, she, likes, english, food, </s>]
==>数组内容在索引[8]处不同,预期:<food>
但为:<food!>
最佳答案
text.split("\\!\\.\\?")
拆分为连续的!
,.
和?
,这不是您想要的
而是使用:
text.split("[!.?]")
输出:(输入:
"This! is a lot? of words. separated by! punctuation?"
)[This, is a lot, of words, separated by, punctuation]
关于java - 分割字符串!在JAVA中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53285637/