- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace 逆向输入字符串
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("输入个字符串谢谢");
- string str = Console.ReadLine();
- //把要反转的字符串传入反转函数
- string strOut = ChangeStr(str.Trim());
- Console.WriteLine(strOut);
- Console.ReadKey();
- }
- static string ChangeStr(string str)
- {
- //初始化一个可变字符串用来存储反转字符串
- StringBuilder strout = new StringBuilder();
- //由大到小的str下标开始插入可变字符串,完成反转过程
- for (int i = str.Length-1; i >= 0; i--)
- {
- strout.Append(str[i]);
- }
- return strout.ToString();//返回
- }
- }
- }
复制代码 |