面对人生

导航

一道C#面试试题

         面试的时候,遇到了这样的一道题,比较Easy,回家后整理了一下。
         写一段小程序 将一个字符串如“I am student” 转换成 “student am I”(不准用C#已有的函数库)
         我是在ASP.NET Web应用程序里写的,运行即可看效果。

 1private void Page_Load(object sender, System.EventArgs e)
 2        {
 3            if(!IsPostBack)
 4            {
 5                string[] str_Test = StrSub("I am student").Split(new char[]{','});
 6
 7                string str_Go = "";
 8                for(int i=str_Test.Length-1;i>=0;i--)
 9                    str_Go += str_Test[i] + " ";
10
11                Response.Write(str_Go);
12            }

13        }

14
15        public string StrSub(string p_Test)
16        {
17            string str_TestTemp = "";
18            string str_Test = "";
19            string str_Test2 = "";
20
21            for(int i=0;i<p_Test.Length;i++)
22            {
23                str_Test2 = p_Test.Substring(i,1).Trim();
24
25                if(str_Test2 != "")
26                    str_Test += str_Test2;
27                else
28                {
29                    str_TestTemp += str_Test + ",";
30                    str_Test = "";
31                }

32            }

33            return str_TestTemp + str_Test;
34        }

posted on 2005-12-05 11:05  面对人生  阅读(922)  评论(4)    收藏  举报