February 22, 2011

String Class Extensions

string.Right() method and case insensisitive IndexOf
String Extension Collection for C#
Favorite String Extension Methods in C#

Convert 'string.Right()' to an extension method
static class StringExtensions
{
  static string Right(this string s, int count )
  {
    string newString = String.Empty;
    if (s != null && count > 0)
    {
      int startIndex = s.Length - count;
      if (startIndex > 0)
        newString = s.Substring( startIndex, count );
      else
        newString = s;
    }
    return newString;
  }
}

No comments: