The input string from which trailing characters should be stripped.
The substring to remove if it appears at the end of the input string.
If true, does not strip the trailing characters when the string is exactly equal to charsToStrip.
The modified string with trailing characters stripped, or the original string if no match is found.
stripTrailingChars("example.txt", ".txt", false); // "example"
stripTrailingChars("example.txt", ".txt", true); // "example"
stripTrailingChars("file.txt", "txt", false); // "file.txt" (no match)
stripTrailingChars(".txt", ".txt", true); // ".txt" (exact match, not stripped)
Removes trailing characters from a string if they match the specified substring.