【发布时间】:2016-09-19 14:24:55
【问题描述】:
如何将一个句子分成两个字数相等的组?
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"
我尝试将整个句子拆分为单词,获取第 ((total number of spaces / 2) + 1)th 个空格的索引并应用子字符串。但这很混乱,我无法得到想要的结果。
【问题讨论】:
-
以下链接可能对您有所帮助。 stackoverflow.com/questions/25853393/…
-
如果一个句子有奇数个单词会怎样?
-
应该是 part[0] = even, part[1]=odd,我已经在我的问题中展示了。
-
你来这里之前有没有尝试过什么?如果是这样,您尝试过什么?那它不起作用怎么办?
-
@amanda014 你是怎么解决你的问题的?