Last active
December 11, 2019 14:45
-
-
Save wood-push-melon/4b4777889d88f637e31ccd04c6bbe820 to your computer and use it in GitHub Desktop.
Sanitizing String Input
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
user_input = "This\nstring has\tsome whitespaces...\r\n" | |
character_map = { | |
ord('\n') : ' ', | |
ord('\t') : ' ', | |
ord('\r') : None | |
} | |
user_input.translate(character_map) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment