如何翻转字符串,如I  am  a  student转成student  a  am  I(不准使用库函数)

解决方案 »

  1.   

    string s="I  am  a  student";
    string news=""; foreach(string t in s.Split(' '))
    {
    news=t+" " + news; }
    news=news.TrimEnd();
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  2.   

    private string 递归(string 字符串)
    {
        if (字符串.Length == 0) return "";
        return 字符串.Substring(字符串.Length - 1) + 
            递归(字符串.Substring(0, 字符串.Length - 1));
    }
    private string 循环(string 字符串)
    {
        string 返回值 = "";
        foreach (char 字符 in 字符串)
            返回值 = 字符 + 返回值;
        return 返回值;
    }
    private void button1_Click(object sender, EventArgs e)
    {
        string S = "I  am  a  student";
        MessageBox.Show(递归(S));
        MessageBox.Show(循环(S));
    }
      

  3.   

    一时手痒,还是帮你做了:
    string s="I  am  a  student";
    String so = "";
    String st = "";
    for (int i = 0; i < s.Length; i++)
    {
        if (s[i] == ' ')
        {
            so = st + " " + so;
            st = ""; 
        }
        else
        {
            st += s[i] + "";
        }
    }
    so = st + " " + so;