Imran Akram's blog

Let's talk about life, technicalities, career opportunities, current affairs and a lot more!

Javascript: String trim functions: leftTrim, rightTrim and trimAll

The first is a definition of the separate function leftTrim, rightTrim and trimAll. These trim the spaces to the left of the string, the right of the string and both sides respectively. function leftTrim(sString) { while (sString.substring(0,1) == ‘ ‘) { sString = sString.substring(1, sString.length); } return sString; } function rightTrim(sString) { while (sString.substring(sString.length-1, sString.length) [...]

  • Share/Bookmark