string mid="3";
string mids="1,2,3,4,5,6";
现在我要的结果是"3,4,5,6,1,2";
如果mid="5"
那么我要结果是"5,6,1,2,3,4"

解决方案 »

  1.   

    string mid = "5";
    string mids = "1,2,3,4,5,6";System.Text.StringBuilder sb = new System.Text.StringBuilder();
    string[] t = mids.Split(',');
    int pos = Convert.ToInt32(mid);
    for(int i = pos;i <= t.Length;i++)
    {
    sb.Append(t[i-1]);
    sb.Append(",");
    }
    for(int i = 1;i < pos;i++)
    {
    sb.Append(t[i-1]);
    sb.Append(",");
    } string newMids = sb.ToString();
    newMids = newMids.Substring(0,newMids.Length - 1);
    Response.Write(newMids);
      

  2.   

    如果
    string mid="b";
    string mids="a,b,g,p,y,z";
    呢?不一定是数字啊!
      

  3.   

    static void Main(string[] args)
    {
        string mid = "b";
        string mids = "a,b,c,d,e";    Console.WriteLine(Order(mid, mids));
        Console.Read();
    }static string Order(string num1, string num2)
    {
        int n1 = (int)Convert.ToChar(num1);
        string[] nums = num2.Split(',');
        int[] ns = new int[nums.Length];    for (int i = 0; i < ns.Length; i++)
            ns[i] = (int)Convert.ToChar(nums[i]);    for( int i = 0; i < ns.Length - 1; i++)
            for (int j = i + 1; j < ns.Length; j++)
                if (ns[i] > ns[j])
                {
                    int tmp = ns[i];
                    ns[i] = ns[j];
                    ns[j] = ns[i];
                }    StringBuilder sbNums = new StringBuilder();    for (int i = 0; i < ns.Length; i++)
            if (ns[i] >= n1)
            {
                for (int j = ns.Length - 1; j >= i; j--)
                    sbNums.Insert(0, (char)ns[j]).Insert(1, ",");
                break;
            }
            else
                sbNums.Append((char)ns[i]).Append(",");    return sbNums.ToString().Substring(0, sbNums.Length - 1);
    }
      

  4.   

    ns[j] = ns[i];-->ns[j] = tmp;//写错了
      

  5.   

    string mid="5";
    string mids="1,2,3,4,5,6";
    string repmids = mids.Replace(",",""); char c = Convert.ToChar(mid);
    string[] str = repmids.Split(c); string newmids = mid + str[1] + str[0]; string relmids = null; for(int i=0;i<newmids.Length;i++)
    {
    if(i == newmids.Length-1)
    relmids += newmids[i]; 
    else
    relmids += newmids[i] + ","; 
    }relmids 就是你想要的string