String.Replace 方法 (Char, Char)

解决方案 »

  1.   

    /// <param name="pos">1 Based</param>
    public string MyReplace(string src,int pos,string newVal)
    {
    if(pos<=0)
    throw new Exception("位置非法!");
    if(pos>src.Length)
    throw new Exception("位置超出原始字符串长度!");
    return src.Replace(src.Substring(pos-1,1),newVal);
    }
    -----------------------------------
    Whgg qb jung lbh jnag gb qb qbqnl !
      

  2.   

    nerk(无) 
    你这样的打击面太大了,我只想换掉那个指定位置的字符,别的位置跟这个字符相同的我并没打算换掉啊
      

  3.   

    sorry我也没看清你的要求
    把最后一行改成这样:return src.Substring(0,pos-1)+newVal+src.Substring(pos+newVal.Length-2);
    ___________________________________
    too simple,sometimes naive :()
    ___________________________________