Suggestion to reverse string in c#
Posted
by HasanGursoy
on Stack Overflow
See other posts from Stack Overflow
or by HasanGursoy
Published on 2010-05-29T12:02:58Z
Indexed on
2010/05/29
12:22 UTC
Read the original article
Hit count: 299
Is this the right method to reverse a string? I'm planning to use it to reverse a string like: Products » X1 » X3 to X3 « X1 « Products I want it to be a global function which can be used elsewhere.
public static string ReverseString(string input, string separator, string outSeparator)
{
string result = String.Empty;
string[] temp = Regex.Split(input, separator, RegexOptions.IgnoreCase);
Array.Reverse(temp);
for (int i = 0; i < temp.Length; i++)
{
result += temp[i] + " " + outSeparator + " ";
}
return result;
}
© Stack Overflow or respective owner