我需要排序帮助
我不知道为什么当我有字符串“3*3”时,matcher.find()会跳转
代码:
public void delSin_Cos_Tan()
{
o = new ArrayList<>();
String aDate = "3*3";
Pattern datePattern = Pattern.compile("((sin|cos|tan|sinh|cosh|tanh|asin|acos|atan)\\((.+)\\))");
//Operat.Sin_Cos_Tan.Patter = ((sin|cos|tan|sinh|cosh|tanh|asin|acos|atan)\((.+)\))
Matcher matcher = datePattern.matcher(aDate);
Log.d(TAG,"Sin Startz");
Log.d(TAG,"Sin " + Aufgabe);
while (matcher.find());
{
Log.e(TAG,matcher.group(1)); // there is the Error, but withe the String "3*3" an i don't konw why it is jump inside the while
String Gesammt = matcher.group(1);
String TYP = matcher.group(2);
String Inklammer = matcher.group(3);
Log.d(TAG, String.valueOf("------------------------"));
Log.d(TAG, Gesammt);
Log.d(TAG, Inklammer);
Log.d(TAG, TYP);
Log.d(TAG, String.valueOf("------------------------"));
}
}
我的完整代码:http://pastebin.com/jWN1ghfz
最佳答案
在 while 循环之后有一个 ;
。
这就是为什么你的完整 block 总是会被执行!
while (matcher.find());
应该是 while (matcher.find())
(没有 ;
)
因为
while (matcher.find());
{
//...
}
与
相同while (matcher.find()){
;
}
{
//...
}
关于java - While(matcher.find()) - 错误 - 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31579895/