无语了,连个if else都不会用啊楼主

解决方案 »

  1.   

    改成这样,勉强运行吧,不过看起来感觉不够简洁
     string str = "123##$$";
     
                if (str.Contains("#"))
                {
                    str = str.Replace("#", "aa");
                }
                if (str.Contains("$"))
                {
                    str = str.Replace("$", "cc");
                }
     
                Console.WriteLine(str);//结果为:123aaaa$$
      

  2.   

    str = str.Replace("$", "cc"); 中的"$" 此处被作为正则表达式解释运行了所以不成功可以像下面这样用正则去替换
                Regex re = new Regex("[$]");
                str = re.Replace(str, "cc");
    str = str.Replace("$", "cc"); 中的"$" 此处被作为正则表达式解释运行了所以不成功可以像下面这样用正则去替换
                Regex re = new Regex("[$]");
                str = re.Replace(str, "cc");
      

  3.   

    string str = "123##$$";            if (str.Contains("#"))
                {
                    str = str.Replace("#", "aa");
                }
                
                if (str.Contains("$"))
                {
                    str = str.Replace("$", "cc");
                }输出:123aaaacccc你原先esele if 有问题。