We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

Memphys on 10/04/06


Tagged

javascript trim


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

tylerhall
luman
rnrleachryan


trim function


Published in: JavaScript 


  1. <script language="JavaScript" type="text/JavaScript">
  2. <!--
  3. function trim(s) {
  4. while (s.substring(0,1) == ' ') {
  5. s = s.substring(1,s.length);
  6. }
  7. while (s.substring(s.length-1,s.length) == ' ') {
  8. s = s.substring(0,s.length-1);
  9. }
  10. return s;
  11. }
  12. //-->
  13. </script>

Report this snippet 

You need to login to post a comment.