日期:2014-05-18  浏览次数:21007 次

c#字符串按照一行一行随机排序问题
有一个string:
aaaaaa\r\n
bbbbbb\r\n
cccccc\r\n
dddddd\r\n
eeeeee\r\n
ffffff\r\n

如何能将这几行打乱顺序
ffffff\r\n
cccccc\r\n
bbbbbb\r\n
aaaaaa\r\n
eeeeee\r\n
dddddd\r\n

------解决方案--------------------
try
C# code
            string strOld = "aaaaaa\r\nbbbbbb\r\ncccccc\r\ndddddd\r\neeeeee\r\nffffff\r\n";
            string[] strTemp = strOld.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            ArrayList alNew = new ArrayList();
            Random r = new Random();
            while (true)
            {
                int i = r.Next(0, strTemp.Length);
                if (!alNew.Contains(strTemp[i]))
                    alNew.Add(strTemp[i]);
                if (alNew.Count == strTemp.Length)
                    break;
            }

            foreach (object obj in alNew)
            {
                Console.WriteLine(obj);
            }