Membuat fungsi trim pada object String di Javascript
Menghapus karakter atau spasi di awal dan akhir string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @param st: The string that will be trimmed. @default whitespace | |
String.prototype.strim = function(st) { | |
st = st || "\\s"; | |
return this.replace(new RegExp("^"+st+"+|"+st+"+$",'g'),''); | |
} | |
/* | |
example: | |
"alorem ipsuma".strim('a'); // return "lorem ipsum" | |
" lorem ipsum ".strim(); // return "lorem ipsum" | |
*/ |
Komentar
Posting Komentar
Komentar ...