[正则表达式]C# 给数字字符串加上千位逗号

欧洲有习惯,每3位数值加个逗号分隔,我写了个这样的正则……

(\d+?)(\d{3})*(\.\d+|$)

然后C# 程序里这样用

 

  private  string FN(string num)
  {
   string newstr = string.Empty;
   Regex r = new Regex(@"(\d+?)(\d{3})*(\.\d+|$)");
   Match m = r.Match(num);
   newstr+=m.Groups[1].Value;
   for(int i =0;i<m.Groups[2].Captures.Count;i++)
   {
    newstr+=","+m.Groups[2].Captures[i].Value;
   }
   newstr+=m.Groups[3].Value;
   return newstr;
  }

posted @ 2009-03-11 16:38  zzh  阅读(2402)  评论(0编辑  收藏  举报