日期:2014-05-20  浏览次数:21013 次

元素合并
arraylist arr=new arraylist();
arr里面有元素:"ff;","aa;","dd;","cc","ee","zz","hh;","pp;"
怎样把连续的且不是以";" 结尾的元素合并

------解决方案--------------------
//不需要.ToList()

var query=arr.ToArray().Select(m=>m.ToString()).Aggregate((a,b)=>a.EndsWith(";")?a+"~"+b:
(a.EndsWith("~")||b.EndsWith("~"))?a.TrimEnd('~')+b.TrimEnd('~')+"~":a+b+"~").Split(new string[]{"~",";"},StringSplitOptions.RemoveEmptyEntries).Select(s=>s+";");