/ Published in: JavaScript
Released into the public domain. Returns a string with leading and trailing spaces from stringToTrim.
Expand |
Embed | Plain Text
function reverseString(strToReverse) { reversedString = ''; for(var i=strToReverse.length-1;i>=0;i--) reversedString += strToReverse[i]; return reversedString; } function trimString(stringToTrim) { var sStart = 0, sEnd = 0; while(stringToTrim[sStart]==' ') sStart++; stringToTrim = reverseString(stringToTrim.substring(sStart)); while(stringToTrim[sEnd]==' ') sEnd++; return reverseString(stringToTrim).substring(0, stringToTrim.length-sEnd); }
You need to login to post a comment.
