有一个字符串 str的值为
(((AND PHONE_C = '1' )OR PHONE_C = '1' )AND PHONE_C = '1' )或者是
(((OR PHONE_C = '1' )OR PHONE_C = '1' )AND PHONE_C = '1' )把第一个AND或是OR达到这样的效果
(((PHONE_C = '1' )OR PHONE_C = '1' )AND PHONE_C = '1' )注释:第一AND或OR前面的括号"("数量不确定,可多可少求解答!

解决方案 »

  1.   

    把第一个AND 或者 OR 去掉?
      

  2.   

    恩 把第一个 AND 或OR 去掉
      

  3.   

    int index = str.IndexOf("P", 0);
    string str1 = str.Substring(0, index).Trim();
    string str2 = str.Substring(index + 1);
    if (str1.EndsWith("AND"))
    {
       str1 = str1.Remove(str1.Length-3, 3);
    }
    else
    {
       str1 = str1.Remove(str1.Length - 2, 2);
    }
    string newStr = str1 + str2;
      

  4.   

    字符串 的字段都是可变的 不一定第一个是PHONE_C继续求解
      

  5.   

    string str1 = "(((OR PHONE_C = '1' )OR PHONE_C = '1' )AND PHONE_C = '1' )";
    string str2 = "((((((AND PHONE_C = '1' )OR PHONE_C = '1' )AND PHONE_C = '1' )";
    Console.WriteLine(Regex.Replace(str1, @"(\(+)(OR +|AND +)?(\.*)", "$1$3"));
    Console.WriteLine(Regex.Replace(str2, @"(\(+)(OR +|AND +)?(\.*)", "$1$3"));
      

  6.   

    0009(夏天以南)重载Replace方法未获取"3"参数
      

  7.   

    using System.Text.RegularExpressions;
      

  8.   

    string str1 = "(((OR PHONE_C = '1' )OR PHONE_C = '1' )AND PHONE_C = '1' )";
    string str2 = "((((((AND PHONE_C = '1' )OR PHONE_C = '1' )AND PHONE_C = '1' )";
    Console.WriteLine(System.Text.RegularExpressions.Regex.Replace(str1, @"(\(+)(OR +|AND +)?(\.*)", "$1$3"));
    Console.WriteLine(System.Text.RegularExpressions.Regex.Replace(str2, @"(\(+)(OR +|AND +)?(\.*)", "$1$3"));
      

  9.   

    @"(\(+)(OR +|AND +)?(\.*)"
    意思就是先将字符串分成三部分,(\(+)代表n个(
    (OR +|AND +) OR  或者 AND
    ?(\.*) 任意字符
    这样就可以将OR或者And从字符串中独立出来了