Reversing Characters : String Insert Replace « String « C# / CSharp Tutorial






using System;
using System.Text;

    class Class1
    {
        [STAThread]
        static void Main(string[] args)
        {
            string str = "abcdefghijklmnopqrstuvwxyz";

            str = ReverseString( str );
            Console.WriteLine( str );

            str = ReverseStringEnum( str );
            Console.WriteLine( str );
        }

        static string ReverseString( string strIn )
        {
            StringBuilder sb = new StringBuilder(strIn.Length);

            for( int i = 0; i < strIn.Length; ++i )
            {
                sb.Append( strIn[(strIn.Length-1)-i] );
            }
            return sb.ToString();
        }

        static string ReverseStringEnum( string strIn )
        {
            StringBuilder sb = new StringBuilder( strIn.Length );
            foreach( char ch in strIn )
            {
                sb.Insert( 0, ch );
            }

            return sb.ToString();
        }
    }








5.15.String Insert Replace
5.15.1.String Inserting
5.15.2.Replace string
5.15.3.Replace characters
5.15.4.Replace substring
5.15.5.Reversing Characters
5.15.6.Reversing a String