Created
September 10, 2020 12:26
-
-
Save supermarsx/5affe2d4c0ad7e0a65c356a7dba56fb3 to your computer and use it in GitHub Desktop.
Trims a given char from a string bounds
This file contains hidden or 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
/* | |
trimChar | |
Trims a specific char from bounds of variable | |
parameters | |
string (string) - String to be trimmed | |
charToRemove (char) - Char to be removed from string | |
*/ | |
function trimChar(string, charToRemove) { | |
while (string.charAt(0) == charToRemove) string = string.substring(1); | |
while (string.charAt(string.length - 1) == charToRemove) string = string.substring(0, string.length - 1); | |
return string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment