Skip to content

Instantly share code, notes, and snippets.

@bharathmuddada
Created July 18, 2022 15:03
Show Gist options
  • Save bharathmuddada/ad031fde4de2d52abfb98d18f9181de2 to your computer and use it in GitHub Desktop.
Save bharathmuddada/ad031fde4de2d52abfb98d18f9181de2 to your computer and use it in GitHub Desktop.
Reversing String
public class StringReversal
{
public static void Main(String[] args)
{
string courseName1 = "Automation";
//Reversing String Approach -01
for (int i = courseName1.Length-1;i>=0 ; i--) {
Console.Write(courseName1[i]);
}
//Below statement is to print a new line
Console.WriteLine();
//Reversing String Approach -02
//Converting string to character Array
string courseName2 = "Automation Testing";
var charArray = courseName2.ToCharArray();
for (int i = charArray.Length-1; i >= 0; i--)
{
Console.Write(charArray[i]);
}
//Below statement is to print a new line
Console.WriteLine();
//Reversing String Approach -02
//Converting string to character Array and using the Array Reverse Method
string courseName3 = "Selenium,Webdriver";
var charArray2 = courseName3.ToCharArray();
Array.Reverse(charArray2);
for (int i = 0; i < charArray2.Length; i++)
{
Console.Write(charArray2[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment