110,532
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
string s = "这串数字1234567891012345678910123456789101234567891012345678910将加上逗号";
string t = Regex.Replace(s, @"(?<=\d)(?=(?:\d\d\d)+(?!\d))", ",");
Console.WriteLine(t);
}
}
string str = Regex.Replace(s, @"(?<=\d)\d{3}", delegate(Match m) { return "," + m.Value; }, RegexOptions.RightToLeft);
string str = Regex.Replace("12345678910", @"\d{3}", delegate(Match m) { return ","+m.Value; }, RegexOptions.RightToLeft);
// 如果一定要用正则表达式,就这样:(优点是可以处理很长的数字串)
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
string s = "1234567891012345678910123456789101234567891012345678910";
string t = Regex.Replace(s, @"(?<=\d)(?=(?:\d\d\d)+$)", ",");
Console.WriteLine(t);
}
}
// 如果不是非要用正则表达式,这样就可以了:
string s = 12345678910.ToString("N0");