请高人指点
比如 把12345678要用递归拆分成12,345,678
       12345 拆分成 12,345
就是按找千分位来拆分.先行谢过了!

解决方案 »

  1.   

    string resultStr = string.Empty;
    public void Sub(string str)
    {
      if(str.Length>0)
      {
        if(str.Length<3)
        {
          resultStr = str +","+ resultStr;
        }
        else
        {
          resultStr = resultStr!=string.Empty?str.Substring(str.Length-3,3)+","+resultStr:str.Substring(str.Length-3,3);
          Sub(str.Substring(0,str.Length-3));
         }
       }
    }
      

  2.   

    你这是拆分还是格式化?如果只是格式化,使用string.Format,或者int.Parse方法,一条语句就搞定了。
      

  3.   

    哈哈,一楼的算法有bugstring resultStr = string.Empty;public void Sub(string str)
    {
        if(str.Length>0)
        {
            if(str.Length<3)
            {
                resultStr = resultStr!=string.Empty ? str +","+ resultStr : str;
            }
            else
            {
                resultStr = resultStr!=string.Empty ? str.Substring(str.Length-3,3)+","+resultStr : str.Substring(str.Length-3,3);
                Sub(str.Substring(0,str.Length-3));
            }
        }
    }
      

  4.   

    string ss = "1234567";
    int cnt = ss.Length%3;
    if (cnt == 1)
    {
    ss = "00" + ss;
    }
    else if (cnt == 2)
    {
    ss = "0" + ss;
    }
    string ResultString = null;
    try 
    {
    ResultString = Regex.Replace(ss, "(\\d{3})", "$1,");

    catch (ArgumentException ex) 
    {
    // Syntax error in the regular expression
    }
    ResultString = ResultString.TrimEnd(",".ToCharArray());
    ResultString = ResultString.TrimStart("0".ToCharArray());
      

  5.   

    我的确实有BUG.你似乎将他完善了.