字符串:That is a hat
反转成:hat is That

解决方案 »

  1.   

    将句子拆分成单词存入List<String>,(string类型有拆分方法) 
    将List<String>反转,
    遍历List<String>拼接字符串,得到结果
      

  2.   


    string strContent = @"That is a hat";
                    string strVlaue = "";
                    Regex re = new Regex(@"[^\s]+");
                    foreach (Match m in re.Matches(strContent))
                    {
                        strVlaue = m.Value.Trim() + " " + strVlaue;
                    }取strVlaue 即可
      

  3.   


    很久以前写的了......不是很好..             int count = 0;
                int begin = 0;
                string txt = "I   am  a programmer";
                Console.WriteLine(txt);
                Console.WriteLine("反转之后");
                for (int i = txt.Length - 1; i >= 0; i--)
                {
                    if (i == txt.Length - 1)
                        count = i;
                    if (i == 0)
                        begin = 0;
                    else
                        begin = i + 1;
                    if (txt[i] == ' ' || i == 0)
                    {
                        for (int j = begin; j <= count; j++)
                            Console.Write(txt[j]);
                        if (i != 0)
                            Console.Write(" ");
                        count = i - 1;
                    }
                }
                Console.Read();
      

  4.   


    string strValue = "That is a hat";
    string[] arrValue = strValue.Split (new char[] { ' ' });
    Array.Reverse (arrValue);
    strValue = string.Join (" ", arrValue);
      

  5.   

    public void test()
            {
                //字符串:That is a hat
                //反转成:hat is That
                string a = "That is a hat";
                string[] b = a.Split(' ');
                string c = string.Empty;
                for (int i = b.Length-1; i >= 0; i--)
                {
                    c += b[i];   
                }
                //输出c的值。
            }
      

  6.   


            public string Reverse(string str)
            {
                string newstr = "";
                string[] list= str.Split(' ');
                for (int i = list.Length; i >0; i--)
                {
                    newstr += list[i - 1]+" ";
                }
                newstr = newstr.Substring(0, newstr.Length - 1);
                return newstr;
            }
      

  7.   

     string str = "That is a hat";
                string[] strArray = str.Split(' ');
                Array.Reverse(strArray);
                 
                 string resultStr = string.Join(" ", strArray);
     
      

  8.   

    Array.Reverse(strArray)  这方法有吗?怎么莪点不出来了?