如何将一个句子分成两组,每个单词的数量相等?按Java计算的单词分词计数
Sentence(odd words count) :
This is a sample sentence
Output: part[0] = "This is a "
part[1] = "sample sentence"
Sentence(even words count) :
This is a sample sentence two
Output: part[0] = "This is a "
part[1] = "sample sentence two"
我试图整个句子分成即,得到的指数((空格/ 2)+ 1总数)个空的空间,并应用串。但它很混乱,我无法得到理想的结果。
以下链接可以帮助你。 http://stackoverflow.com/questions/25853393/split-a-string-in-java-into-equal-length-substrings-while-maintaining-word-bound – user6837640
如果一个句子有单数的单词会发生什么? –
它应该像我的问题中显示的part [0] = even,part [1] = odd。 – amanda014