Switch to full style
JavaScript code examples
Post a reply

Trim string in JavaScript

Wed Oct 26, 2011 12:08 am

Trim string in JavaScript
Code:

function Trim
(str)

{

    while (str.substring(0,1) == ' ') // check for white spaces from beginning

    {

        str = str.substring(1, str.length);

    }

    while (str.substring(str.length-1, str.length) == ' ') // check white space from end

    {

        str = str.substring(0,str.length-1);

    }

   

    return str
;

}
 




Post a reply
  Related Posts  to : Trim string in JavaScript
 remove space ,trim strings from left side ,right side ,both.     -  
 check if string ends with specific sub-string in php     -  
 check if string start with a specific sub-string in PHP     -  
 recursive string reversal- reverse string     -  
 Splitting a String Based on a Found String     -  
 String token for string split     -  
 Pad a string to a certain length with another string     -  
 find a string     -  
 what is string toString()     -  
 get string length in asp     -  

Topic Tags

JavaScript Strings