Posted By

wak47 on 07/02/09


Tagged


Versions (?)

javascript left right functions


 / Published in: JavaScript
 

  1. function Left(str, n){
  2. if (n <= 0)
  3. return "";
  4. else if (n > String(str).length)
  5. return str;
  6. else
  7. return String(str).substring(0,n);
  8. }
  9.  
  10. function Right(str, n){
  11. if (n <= 0)
  12. return "";
  13. else if (n > String(str).length)
  14. return str;
  15. else {
  16. var iLen = String(str).length;
  17. return String(str).substring(iLen, iLen - n);
  18. }
  19. }

Report this snippet  

You need to login to post a comment.