Home
Manage Your Code
Snippet: String Right (C#)
Title: String Right Language: C#
Description: Noticeably absent from the string class is the Right method. But you can replicate it easily using the Substring method. Here is a simple method that wraps this up nicely: Views: 1029
Author: joe sopcich Date Added: 9/5/2008
Copy Code  
1static string Right( string s, int count )
2{
3    string newString = String.Empty;
4    if (s != null && count > 0)
5    {
6        int startIndex = s.Length - count;
7        if (startIndex > 0)
8            newString = s.Substring( startIndex, count );
9        else
10            newString = s;
11    }
12    return newString;
13}