Friday, April 6, 2012

String Reverse without BuiltIn function.....

  • Here we are extensively using string builder class which is mutable, ie editable. In other words it does not create a new copy during the operations as opposed to string class.
  • It is a best practice to try with static methods and classes which are not instance specific
  • We remember string is array of chars....
 static string stringreverse(string input)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = input.Length-1; i >= 0; i--)
            {
                sb.Append(input[i]);

            }

            return sb.ToString();
        }