一个有趣的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://laoyebin.cnblogs.com/
个人网站英文出处: http://mrvsto.com/
个人网站中文出处: http://cn.mrvsto.com/

你可能感兴趣的:(String,C#,regex,input,2010)