【发布时间】:2014-01-04 01:00:54
【问题描述】:
任务是从句子中删除字母 i。
public static void main(String[] args) {
int index = 8;
String letter = "i";
String text = "method appends the string to the end. t is overloaded to have the following forms.";
StringBuffer sb = new StringBuffer(text);
Pattern pat = Pattern.compile(letter);
Matcher mat = pat.matcher(sb);
//while (mat.find()) -throws StringIndexOutOfBoundsException.
while (mat.find(0)){
sb.deleteCharAt(mat.start());
}
System.out.println(sb.toString());
}
好吧,程序有效,但我不明白为什么明显的方法无效?
【问题讨论】: