javascript left right functions


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.