日期:2014-05-17 浏览次数:20972 次
string old="1/200;2/300;3/300;4/500;20/600;23/700;24/700;25/700;26/700";
var res = string.Join(";", old.Split(';').GroupBy(p => Convert.ToInt32(p.Split('/')[1])).Select(p => String.Join("-", p.Select(c => c.Split('/')[0])) + "/" + p.Key.ToString()));
var res1 = string.Join(";",
old.Split(';')
.Select(p =>
{
var t = p.Split('/');
return new { id = t[0], num = Convert.ToInt32(t[1]) };
})
.GroupBy(p => p.num)
.Select(p => string.Join("-", p.Select(c => c.id)) + "/" + p.Key.ToString()));
string str = "1/200;2/300;3/300;4/500;20/600;23/700;24/700;25/700;26/700";
//str = Regex.Replace(str, @"(\d+)/(\d+);((\d+)/\2(;
------解决方案--------------------
$))+", "$1-$4/$2;");
str = Regex.Replace(str, @"(\d+)/(\d+);((\d+)/\2(;
------解决方案--------------------
$))+", delegate(Match m)
{
string s = "";
int n = Convert.ToInt32(m.Groups[1].Value);
var list = m.Groups[4].Captures.OfType<Capture>().Select(t => Convert.ToInt32(t.Value)).ToList();
for (int i = 0; i < list.Count; i++)
{