056
}else{
Patternpattern=Patternpile(regex);
}else{
083
matcher=pattern.matcher(string);
075
}
055
068
string=string.replaceAll(“\\s“,““);//去除空格
}
073
string=computeStirngNoBracket(string);
082
while(matcher.find()){
computeStirngNoBracket(temp)
temp=matcher.group();
078
077
060
053
DecimalFormatdecimalFormat=newDecimalFormat(format);
093
//循环计算所有括号里的表达式
//最后计算总的表达式结果
067
086
*@return
097
}catch(Exceptione){
092
StringregexCheck=“[\\(\\)\\d\\ \\-\\*/\\.]*“;//是否是合法的表达式
057
NumberFormatnumberFormat=NumberFormat.getInstance();
061
071
065
058
Stringtemp=““;
072
returns;
*计算字符串四则运算表达式
059
s=numberFormat.format(obj);
090
054
074
069
publicstaticStringcomputeString(Stringstring){
si m i s h u wu. c o m
while(pattern.matcher(string).find()){
076
Matchermatcher=null;
080
try{
Stringregex=“\\([\\d\\.\\ \\-\\*/] \\)“;//提取括号表达式
returnstring;
081
070
}
085
index=string.indexOf(temp);
063
079
string=string.substring(0,index)
returne.getMessage();(未完待续。)
087
094
*/
089
string.substring(index temp.length());
066
096
}catch(NumberFormatExceptione){
095
*@paramstring
062
/**
}
064
intindex=-1;
052
091
s=decimalFormat.format(obj);
}
if(!Pattern.matches(regexCheck,string))
084
}
088