一个有趣的C#正则替换问题
9.1(2) ------ 9.11
9(3).5(1) ----- 999.5
89(2).7 ------ 899.7
即把括号替换成括号前一数字的N次
原帖见http://topic.csdn.net/u/20100317/19/e25694b8-ff80-427a-910b-04a666ce6cbc.html
static void Main(string[] args)
{
string[] input = { "9.1(2)", "9(3).5(1)", "89(2).7" };
Regex reg = new Regex(@"(\d)\((\d+)\)");
foreach (string s in input)
{
Console.WriteLine("源字符串:" + s.PadRight(15, ' ') + " 替换结果:" + reg.Replace(s, delegate(Match m) { return new string(m.Groups[1].Value[0], Convert.ToInt32(m.Groups[2].Value)); }) + "\n");
}
}
作者:laoyebin(Paladin.lao)
出处:http://www.cnblogs.com/laoyebin/
网赚 :https://laoyebin.com/
优惠码发布:https://yhmfb.com/
导读网:https://daodu.co/
外汇吧:https://waihui.pub/
本文版权归作者和博客园共有,欢迎转载,但请保留作者信息和原文链接,非常感谢。

浙公网安备 33010602011771号
反馈文章质量,你可以通过快速通道评论: