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