Reverse Word In String in C#
Words in a string can be reversed. We have several methods or ways to reverse word in a string.
Using C# you can reverse string:
Example:
char [] charAray = "This is Test String".ToCharArray();
StringBuilder sb = new
StringBuilder();
System.Console.WriteLine((new string(charAray)));
System.Console.WriteLine("Reverse");
for(int
i=charAray.Length-1;i>=0 ;i--)
{
if (charAray[i] == ' ')
{
char[] charAray1 =
sb.ToString().ToCharArray();
Array.Reverse(charAray1);
System.Console.Write(new string(charAray1)
+ " ");
sb.Clear();
}
else
{
sb.Append(charAray[i]);
}
}
char[] temp = sb.ToString().ToCharArray();
Array.Reverse(temp);
System.Console.Write(new string(temp));
No comments:
Post a Comment