我在前台传入sql的条件诸如:aaa>'100' and  bbb<='200'
aaa和bbb是两个字段名
我在后台获取到这个条件后,还想获取这两个字段名,请问从上面:aaa>'100' and  bbb<='200'这个字符串中该如何截取?谢谢大家

解决方案 »

  1.   

    把aaa和bbb也该成变量作为参数传递不就可以了
      

  2.   

    string aaa;
    string bbb
    string sql;
    sql= aaa+"<100 and "+bbb+">100"
      

  3.   

    不明白题意从aaa>'100' and  bbb<='200'中,截取出什么?
      

  4.   

    string aaa="aaa";
    string bbb="bbb";
    string sql;
    sql= aaa+"<100 and "+bbb+">100"
    然后你想怎么拿都可以
      

  5.   

    public static bool GetCondition(string strSentence, out double outCondition)
            {
                Match res = Regex.Match(strSentence, @"(?<=[<>=]+?')\d+\.?\d*(?=')");
                if (res.Success)
                {
                    if (double.TryParse(res.Value,out outCondition))
                    {
                        return true;
                    }
                }
                outCondition = 0;
                return false;
            }然后使用方法如下:
    string strSource = "aaa>'100' and  bbb<='200'";
    double dCondition;
    if (GetCondition(strSource, out dCondition))
    {
                //dCondition可以用了
    }
      

  6.   

    例如 :
    前台 *.aspx?condition=aaa>'100' and  bbb<='200';
    后台 string x=request.querystring["condition"]
    就是说我想从x中获取出aaa和bbb来。就是上面sql条件的字段名
      

  7.   

    回头看了以下,自己都觉得无法使用。修改:
    public static bool GetCondition(string strSentence,string strField, out double outCondition)
            {
                Match res = Regex.Match(strSentence, @"(?<=" + strField + @"[<>=]+?')\d+\.?\d*(?=')",RegexOptions.IgnoreCase);
                if (res.Success)
                {
                    if (double.TryParse(res.Value,out outCondition))
                    {
                        return true;
                    }
                }
                outCondition = 0;
                return false;
            }使用:
    private void button5_Click(object sender, EventArgs e)
            {
                string strSource = "aaa>'100' and  bbb<='200'";
                double dCondition;
                if (GetCondition(strSource,"aaa", out dCondition))
                {
                    dCondition++;
                }
                if (GetCondition(strSource, "BBB", out dCondition))
                {
                    dCondition++;
                }
            }
      

  8.   

    例如 :
    前台 *.aspx?condition=aaa>'100' and  bbb<='200';
    后台 string x=request.querystring["condition"]
    就是说我想从x中获取出aaa和bbb来。就是上面sql条件的字段名
    如果从*.aspx?condition=aaa>'100' and  bbb<='200';
    获取到
    aaa>'100' and  bbb<='200'
    那你可以这样作
    string strAspCode = @"*.aspx?condition=aaa>'100' and  bbb<='200';";
                Match result = Regex.Match(strAspCode,@"(?<=condition=)[^;]+?(?=;)");
                if(result.Success)
                {
                    MessageBox.Show(result.Value);
                }