【发布时间】:2014-03-12 12:39:09
【问题描述】:
我有以下文本字符串,由一个文本块组成,后跟两个或多个 换行符(\n 可能是 \r)后跟另一个文本块,等等
多行文字
(两个或更多换行符)
多行特克斯
(两个或更多换行符)
我想将这个字符串分成与文本块数量一样多的子字符串,使用新行作为中断边界。
我试过了
public static int indexOf(Pattern pattern, String s) {
Matcher matcher = pattern.matcher(s);
return matcher.find() ? matcher.start() : -1;
}
pStart[i-1] = start + indexOf(Pattern.compile("[\\n\\n]+"), text.substring(start));
但它不起作用。
有没有更好的处理办法?
【问题讨论】: