/**
* 通过分隔符拆分句子,并保留分隔符
*
* @return
*/
public static String[] splitSentence(String sentence,String chars){
//1. 定义匹配模式
Pattern p = Pattern.compile(chars);
Matcher m = p.matcher(sentence);
//2. 拆分句子[拆分后的句子符号也没了]
String[] words = p.split(sentence);
//3. 保留原来的分隔符
if(words.length > 0){
int count = 0;
while(count < words.length){
if(m.find()){
words[count] += m.group();
}
count++;
}
}
return words;
}
08-07
717