Posted By

enochrisen on 11/01/06


Tagged

String function break


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

enochrisen
shachi


breakString


 / Published in: JavaScript
 

  1. <script type="text/javascript">
  2. //<![CDATA[
  3.  
  4. function breakString(breakMe,breakAt) {
  5. breakStr = arguments[2] || '\n';
  6. nbreaks = breakMe.length/breakAt;
  7. for(ret='',i=0;ret+=breakMe.substr(breakAt*i,breakAt)+breakStr,i<nbreaks;i++);
  8. return ret;
  9. }
  10.  
  11. // or even
  12.  
  13. String.prototype.break =
  14. function(breakAt) {
  15. breakStr = arguments[1] || '\n';
  16. nbreaks = this.length/breakAt;
  17. for(ret='',i=0;ret+=this.substr(breakAt*i,breakAt)+breakStr,i<nbreaks;i++);
  18. return ret;
  19. };
  20.  
  21. //]]>
  22. </script>

Report this snippet  

You need to login to post a comment.