zoukankan      html  css  js  c++  java
  • 字符串里面的单词反转

    字符串里面的单词反转,可以用string/stringBuilder

    View Code
    using System;
    using System.Collections;
    using System.Text;
    
    namespace InsertionSorter
    {
        public static class InsertionSorter
        {
            public static string ReverseString(string str)
            {
                string result = null;
                string[] s = str.Split(' ');
                for (int i = 0; i < s.Length; i++)
                {
                    for (int j = s[i].Length - 1; j >= 0; j--)
                    {
                        result += (s[i])[j];
                    }
    
                    result += " ";
                }
    
                return result;
                //Result: siht si a .tset 
            }
            public static string StrReverse(string str)
            {
                StringBuilder sb = new StringBuilder();
                string[] s = str.Split(' ');
                for (int i = 0; i < s.Length; i++)
                {
                    sb.Append(Reverse(s[i]) + " ");
                }
    
                return sb.ToString();
                //Result: siht si a .tset 
            }
            private static string Reverse(string str)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = str.Length - 1; i >= 0; i--)
                {
                    sb.Append(str[i]);
                }
    
                return sb.ToString();
            }
        }
        public class MainClass
        {
            public static void Main()
            {
                string result = null;
                string thisString = "this is a test.";
                InsertionSorter.ReverseString(thisString);
                result = InsertionSorter.StrReverse(thisString);
    
                Console.WriteLine(result);
    
            }
        }
    }
  • 相关阅读:
    VHDL硬件描述语言(三)——基本数据对象和数据类型
    VHDL硬件描述语言(二)——子程序
    VHDL硬件描述语言(一)——基本结构
    C#类
    C#基本语法
    C#的简单数据类型
    C#与.NET
    ARP
    IPv6
    以太网
  • 原文地址:https://www.cnblogs.com/binyao/p/3054284.html
Copyright © 2011-2022 走看看