ini code buat nge-trim/ ngilangin karakter khusus dalam string
yang dihilangkan adalah
- ” ” / spasi
- “\t” tab
- “\n” baris baru/ new line
- “\r” return
- “\0″ Nul-byte
- “\x0B” tab Vertical
function trim(str, chars) {
return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
No comments:
Post a Comment