JavaScript Trim String


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



Copy this code and paste it in your HTML
  1. function trim(strText) {
  2. while('' + strText.charAt(0) == ' ') {
  3. strText = strText.substring(1, strText.length);
  4. }
  5. while('' + strText.charAt(strText.length-1)==' ') {
  6. strText = strText.substring(0, strText.length-1);
  7. }
  8. return strText;
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.