Trim is a good features when you try to delete the space at the left most, right most or both the left most and right most of the string. The following trim function is ultilize the javascript Regular expression for the trim function
Left Trim
function ltrim(str){
return str.replace(/^s+/, ”);
}
Right Trim
function rtrim(str) {
return str.replace(/s+$/, ”);
}
All trim
function alltrim(str) {
return str.replace(/^s+|s+$/g, ”);
}
More From david_cheong
david_cheong Recommends
- Improved features in Windows 8 – Preview (Sathiya seelan)
- How to fit more than a thousand words into a tweet (Sathiya seelan)
Popularity: 1% [?]
No related posts.






Comments
No Responses to “Trim a string in Javascript”