User Id :    Password :      New Member   Forgot Password  
Topic: How to trim exra spaces from a string in javascript?
Ferhan Siddiqui
24 Aug 2011 at 11:29 AM

Hi there,

How to trim exra spaces from a string in javascript?

Please help.


Re: How to trim exra spaces from a string in javascript?
Najmul Hoda
24 Aug 2011 at 05:42 PM

Hi ferhan,

Please use below codesnippet.


function trim(str) {
    while (str.charAt(0) == " ") {
        // remove leading spaces
        str = str.substring(1);
    }
    while (str.charAt(str.length - 1) == " ") {
        // remove trailing spaces
        str = str.substring(0, str.length - 1);
    }
    return str;
}
Total Replies: 1
 
Featured Text Ad

Featured Ad