VB string.left and string.right as C# Extension methods on string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mmsaffari
    New Member
    • Oct 2011
    • 2

    VB string.left and string.right as C# Extension methods on string

    Perhaps these 2 tiny methods I'm sharing here come handy to someone.
    Code:
    		public static string Left(this string input, int length) {
    			string result = input;
    			if (input != null && input.Length > length) {
    				result = input.Substring(0, length);
    			}
    			return result;
    		}
    
    		public static string Right(this string input, int length) {
    			string result = input;
    			if (input != null && input.Length > length) {
    				result = input.Substring(input.Length - length, length);
    			}
    			return result;
    		}
    Last edited by Niheel; Oct 5 '11, 03:59 PM. Reason: Can you post an explanation of what they do and how to use them? Insights have to more like articles than just code.
Working...