如何成批替换字符串中的同一个字符?例如替换字符串"abca"中的"a"?
有无这样的方法或函数一次性替换?

解决方案 »

  1.   

    string s = "abca";
    s = s.Replace('a', 'x');
      

  2.   

      String str = "ababa";
      String strs= str.Replace("a", "1")
      MessageBox.Show(strs)//"1b1b1"
      

  3.   

    给你举个例子:
    string s="abca";
    使用string的replace(string oldValue,string newValue)方法;
    这个方法会把s中所有的oldValue替换为newValue;
    是不是符合你的要求?
      

  4.   

    是要替换文章中所有的a,还是只替换文章中字符串abca 中的a?
      

  5.   

    replace函数,或用正则都可以。