• 字符串反转的几种方法


    class Program
        {
            static void Main(string[] args)
            {
                string test = "this is test case";
                //except result="esac tset si siht";
                string result1 = Reserve1(test);
                string result2 = Reserve2(test);
                string result3 = Reserve3(test);
            }
    
            public static string Reserve1(string str)
            {
                string result = null;
                for (int i = str.Length - 1; i >= 0; i--)
                {
                    result += str[i];
                }
    
                return result;
            }
    
            public static string Reserve2(string str)
            {
                Hashtable hs = new Hashtable();
                int i = 0;
                foreach (char c in str)
                {
                    hs.Add(i, c);
                    ++i;
                }
    
                string result = null;
                foreach (DictionaryEntry c in hs)
                {
                    result += c.Value;
                }
    
                return result;
            }
    
            public static string Reserve3(string str)
            {
                Stack stack = new Stack();
                foreach (char c in str)
                {
                    stack.Push(c);
                }
                
                string result = null;
                foreach (var c in stack)
                {
                    result += c.ToString();
                }
    
                return result;
            }
    View Code
  • 相关阅读:
    mongodb导入导出
    python笔记1
    C# 文件下载断点续传
    热水维修记事
    memcached笔记
    模拟登陆
    Nginx学习笔记之加强篇
    Redis学习笔记之基础篇
    Nginx学习笔记之应用篇
    Nginx 学习笔记之安装篇
  • 原文地址:https://www.cnblogs.com/binyao/p/4921718.html
Copyright © 2020-2023  润新知