我正在尝试编写代码以从段落中删除整个句子。它是哪一个句子并不重要,但它必须至少是一个。
String edit = "The cow goes moo. The cow goes boo. The cow goes roo. The cow goes jew.";
int sentencestart = (edit.substring(edit.length()/2).indexOf('.') + edit.length()/2);
int sentenceend = edit.substring(sentencestart).indexOf('.') + sentencestart;
edit = edit.substring(0, sentencestart) + edit.substring(sentenceend);
System.out.println(edit);
这是我目前拥有的代码。它目前正在打印与我开始时完全相同的字符串。有人有想法么?
编辑:我错误地暗示应该删除任何句子。我的意思是除了第一句话之外的任何句子。最好将要删除的句子落在字符串中间的某个位置,并且实际应用程序将用于非常大的字符串。