//用正则表达式完成替换计算 //检验 if(Common.GetMatchStr(this.sumitem,@"\w+([+\-*/]\w+)*").Length!=sumitem.Length) return -1; string op=Common.GetMatchStr(sumitem,@"^\w+"); double ret=Cvt(op); while(op.Length !=sumitem.Length ) // { string oper=sumitem.Substring(op.Length,1); sumitem=sumitem.Substring(op.Length+1); op=Common.GetMatchStr(sumitem,@"^\w+"); double opval=Cvt(op); switch(oper) { case "+": ret+=opval; break; case "-": ret-=opval; break; case "*": ret*=opval; break; case "/": ret/=opval; break; } } 暂时不支持运算符的优先级和括号。 转载于:https://www.cnblogs.com/jetz/archive/2006/07/12/449299.html