你能帮我吗?Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
运行此程序时出现错误。如何修复 rhi?StringBuffer 和 StringTokenizer 是必需的。另外,如何才能更简单?
import java.util.StringTokenizer;
public class main {
public static int i, n;
public static boolean orly = false;
public static StringBuffer input, tokenStr;
public static StringTokenizer out;
public static char aChar;
public static void main(String[] args) {
input = new StringBuffer("some text");
System.out.println("Начальная строка - " + input.toString());
input = new StringBuffer(input.toString().replaceAll("[^a-z A-Z А-Я а-я]", ""));
if (input.toString().trim().length() != 0) {
out = new StringTokenizer(input.toString());
System.out.println("Форматированая строка - " + input.toString());
n = (out.countTokens());
String[] charSet = { "a", "e", "o", "u", "y" };
for (i = 0; i <= n - 1; i++) {
tokenStr = new StringBuffer(out.nextToken());
aChar = (tokenStr.charAt(0));
String firstchar = tokenStr.toString().substring(0,1);
if (tokenStr.length() > 1) {
for (int i = 0; i <= charSet.length-1; i++) {
if ((!firstchar.equals(charSet[i])) || (!firstchar.toUpperCase().equals(charSet[i]))) {
input.delete(input.indexOf(tokenStr.toString()),input.indexOf(tokenStr.toString())+ tokenStr.length() + 1);
}
}
} else {
input.deleteCharAt(input.indexOf(tokenStr.toString()));
}
}
}
}
}