Skip to content

Instantly share code, notes, and snippets.

@supermarsx
Created September 10, 2020 12:26
Show Gist options
  • Save supermarsx/5affe2d4c0ad7e0a65c356a7dba56fb3 to your computer and use it in GitHub Desktop.
Save supermarsx/5affe2d4c0ad7e0a65c356a7dba56fb3 to your computer and use it in GitHub Desktop.
Trims a given char from a string bounds
/*
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