C# String Left and Right


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public static string Left(string param, int length)
  2. {
  3. //we start at 0 since we want to get the characters starting from the
  4. //left and with the specified lenght and assign it to a variable
  5. string result = param.Substring(0, length);
  6. //return the result of the operation
  7. return result;
  8. }
  9. public static string Right(string param, int length)
  10. {
  11. //start at the index based on the lenght of the sting minus
  12. //the specified lenght and assign it a variable
  13. string result = param.Substring(param.Length - length, length);
  14. //return the result of the operation
  15. return result;
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.