str = str.PadRight(3,"0");不就行了。

解决方案 »

  1.   

    楼上的假如我的str不一定是“中国”。是不确定的,那怎么办。
      

  2.   

    public static void FillSection(ref string strSrcString, string strSectionName,string strNewValue)
            {
                int i = 0;
                int k = 0;
                int len = 0;
                string s = "";
                i = strSrcString.IndexOf(strSectionName);
                if (i>0)
                {
                    k = strSrcString.IndexOf("]", i);
                    len = k - i + 2;
                    strSrcString = strSrcString.Remove(i-1, len);
                    int nSpace = len -Encoding.Default.GetByteCount(strNewValue.Trim().ToCharArray());
                    if (nSpace < 0)
                    {
                        return ;
                    }
                    string val = strNewValue + s.PadRight(nSpace);
                    strSrcString = strSrcString.Insert(i-1, val);
                }
            }