Here's a function to remove spaces from beginning and end of a string. Not much to it...hope you like it.
Code:function Trim( strString ) { //Removes leading and trailing spaces from a string. try { //If parameter was null, return an empty string. if (strString==null) { return ""; } var strNewString = ""; var c = 0; for (i=0; i<strString.length; i++) { if (strString.charAt(i) != " " || c > 0) { strNewString += strString.charAt(i); if (strString.charAt(i) != " ") c = strNewString.length; } } return strNewString.substr(0,c); } catch(e) { //your error handler here } }



Reply With Quote

Bookmarks