Posted By

spark9 on 02/28/09


Tagged

String


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

paelgr
umang_nine


C# String Left and Right


 / Published in: C#
 

  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  

You need to login to post a comment.