Posted By

rtipton on 11/01/09


Tagged

String reverse stringbuilder


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

fredblogs
khouser


Reverse String


 / Published in: C#
 

  1. using System;
  2. using System.Text;
  3.  
  4. namespace ReverseCs
  5. {
  6. class RevString
  7. {
  8. static void Main(string[] args)
  9. {
  10. string inputString = Console.ReadLine();
  11. StringBuilder workString = new StringBuilder(inputString);
  12. StringBuilder reversed = new StringBuilder();
  13.  
  14. int len = workString.Length;
  15. for (int i = len - 1; i >= 0; i--)
  16. reversed.Append(workString[i]);
  17.  
  18. Console.WriteLine("");
  19. Console.WriteLine("Original Text: {0}", workString);
  20. Console.WriteLine("Reversed Text: {0}", reversed.ToString());
  21. }
  22. }
  23. }

Report this snippet  

You need to login to post a comment.