日期:2014-05-17  浏览次数:20365 次

关于字符串的拆分
字符串的格式为如下:
.00(2),7.00(1),8.00(4),
现在想把字符串拆分成如下格式:
.00,.00,7.00,8.00,8.00,8.00,8.00
意思是:如果括号里面的数为2,就把括号前的字符写两份,用,分隔。。。
多谢。。。
------解决方案--------------------

string str = ".00(2),7.00(1),8.00(4),";
          str = Regex.Replace(str, @"(\d*?\.\d+)\((\d+)\)(?=[,,]
------解决方案--------------------
$)", delegate(Match m)
            {
                string source = "";
                int n = Convert.ToInt32(m.Groups[2].Value);
                for (int i = 0; i < n; i++)
                    source += m.Groups[1].Value + (i < n - 1 ? "," : "");
                return source;

            });