Last active
May 29, 2023 03:03
-
-
Save anovsiradj/bc72ea2c3d2dd692411b to your computer and use it in GitHub Desktop.
Javascript String Trim. Deprecated by https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim
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" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment