希望众高手帮帮忙啦,给点提示也好,谢谢了,我找遍了MSDN都找不到有用的。

解决方案 »

  1.   

    反正最后都要用到
    System.Convert.ToInt32(  );
    哈哈
      

  2.   

    在字符串中,运算自动进行,结果还是字符串,你可用MessageBox.show(mysr)察看结果。
    若转换为整数可用System.Convert.ToInt32(string *)
    a = System.Convert.ToInt32(mysr)
      

  3.   

    我是用替换的方法来实现的,效率比较差。
    把括号中的先算好,再用结果替换掉字符串的括号部分。下面是java写的一部分:
    /**
     * 进行+/-*运算
     * String formula 表达式
     * return String .
     * 12-tan30-89/cos20*65+78*sin30
     */
    public String SimpleOperation(String formula){
    this.equation =new Equation (formula);
    Vector vOperation=this.equation.getEquationOperators (formula,true);
    //Vector vNum=this.equation.getEquationOperators (formula,false); 

    Enumeration enum=vOperation.elements ();
    String oper="";
    String formula1=formula;

    //先处理sin,cos ,tan...
    while(enum.hasMoreElements ()){
    oper=(String)enum.nextElement ();

    if((this.operatortype .getType (oper)>this.operatortype.DIGIT)&&(this.operatortype .getType (oper)<this.operatortype.PLUS)){
    int pos1=formula1.indexOf (oper);
    int pos2=pos1+oper.length();
    char ch;
    while(pos2<formula1.length ()){
    ch=formula1.charAt (pos2);//formula.indexOf ("",pos1+1);

    if(!Character.isDigit(ch) ){
    if((ch=='.')){//sin0.68
    pos2++;
    continue;
    }
    if((ch=='-')&&
       (Character.isLetter (formula1.charAt (pos2-1)))){//sin85--9
    pos2++;
    continue;
    }
    break;
    }
    pos2++;
    }
    pos2--;
    String strtemp=formula1;
    strtemp=formula1.substring (pos1,pos2+1);
    Equation equ=new Equation (strtemp);
    if(equ.parse()){
    strtemp=""+this.Equationcalculate (equ);
      formula1=this.StringRelace(pos1,pos2,formula1,strtemp);
    }
    }
    }我的程序能运算
    //$fraction=3//$aaa=100.783516
    //$bbb=$aaa+200
    //$formula=$aaa+$bbb+100
    //$ccc=$aaa//$fraction=5
    //$p0=103
    //$p1=108.56
    //$p2=104.18
    //$up1=0.01
    //$formula=$up1*SQRT(POW(((LN$p0-LN$p2)/($p1*(POW((LN$p1-LN$p2),2)))),2)+POW(((LN$p1-LN$p0)/($p2*(POW((LN$p1-LN$p2),2)))),2))输出结果和下面的类似:
    ?
    ------   Results Content   ------
    result:$formula=$aaa+$bbb+100=501.568
    result:$formula=$up1*SQRT(POW(((LN$p0-LN$p2)/($p1*(POW((LN$p1-LN$p2),2)))),2)+POW(((LN$p1-LN$p0)/($p2*(POW((LN$p1-LN$p2),2)))),2))=0.00303
    ------   Completed!   ------
      

  4.   

    a = System.Convert.ToInt32(mysr)这方法不好用,无法识别的字符,括号与运算符都无法识别啊。
      

  5.   

    1、方法一,用newman0708(nch)
    2、方法二,用string str =  "select " + "int1 = (1+2+3+4)*5-6+7/8",当做一条sql语句执行,需要连接数据库
    3、方法三, 用Datatable的select 结合2(没试过,可以试试)
      

  6.   

    用javascript呵呵,里面有个语句直接可以转化为表达式,恩,我忘记了怎么写
    不知道对你有否帮助
      

  7.   

    差不多是个编译器
    1、词法分析 分析各个元素,包括数字和运算符(正规表达式)
    2、语法分析 分析是否为有效的表达式 (BNF)
    3、语义分析 分析表达式的含义,如何运算 (运算符优先级)
    4、运算 可以用栈实现我写过一个用System.Collection.Stack类计算表达式结果的程序
    可以输出每一步的演算过程。