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

字符串位置互换问题
11为数字组成的字符串,我想把数字顺序打乱一下,用下面的办法好像有问题,麻烦高手看一下行不行
C# code

        public string swapChar(string s)
        {
            char[] newStr = s.ToCharArray();
            newStr[0] = s[10];
            newStr[1] = s[4];
            newStr[10] = s[5];
            newStr[4] = s[7];
            newStr[8] = s[2];
            newStr[10] = s[3];
            return new string(newStr);
        }



------解决方案--------------------
探讨
11为数字组成的字符串,我想把数字顺序打乱一下,用下面的办法好像有问题,麻烦高手看一下行不行
C# code

public string swapChar(string s)
{
char[] newStr = s.ToCharArray();
newStr[0] = s[10];
new……

------解决方案--------------------
这个问题也提了好几遍了
C# code
using System.Linq;

var newStr = new string(str.ToCharArray().OrderBy(e => Guid.NewGuid()));