Posted By

lfatr on 02/16/10


Tagged

String


Versions (?)

SHORTEN STRING AFTER XX LETTERS AND ADD A DELIMITER (...)


 / Published in: JavaScript
 

  1. function shortenString(string, maxlen, del) {
  2. string = string.toString();
  3. if (!del) { del='...' }
  4. if (string.length > maxlen) {
  5. string = string.substr(0, maxlen) + del;
  6. }
  7. return string;
  8. }
  9.  
  10. shortenString('some functions are just useful', 10)

Report this snippet  

You need to login to post a comment.