Simple way to Flip a string

I just thought sometimes simple extensions helps a lot. Like this Flip.

public static string Flip(this string target, bool trimEnds)
{
if (trimEnds) target= target.TrimIfNotNull();
var len = target.Length;
var newString = new string[len];


foreach (var c in target)
{
var temp = len;
newString[temp - 1] = c.ToString();
len--;
}

return string.Join(string.Empty, newString);
}

Call it this way

var returnString = mystring.Flip(true);

Leave a Reply

Your email address will not be published. Required fields are marked *