Created
July 26, 2018 20:00
-
-
Save johnberroa/cd49976220933a2c881e89b69699f2f7 to your computer and use it in GitHub Desktop.
Remove umlauts from text in Python
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
def remove_umlaut(string): | |
""" | |
Removes umlauts from strings and replaces them with the letter+e convention | |
:param string: string to remove umlauts from | |
:return: unumlauted string | |
""" | |
u = 'ü'.encode() | |
U = 'Ü'.encode() | |
a = 'ä'.encode() | |
A = 'Ä'.encode() | |
o = 'ö'.encode() | |
O = 'Ö'.encode() | |
ss = 'ß'.encode() | |
string = string.encode() | |
string = string.replace(u, b'ue') | |
string = string.replace(U, b'Ue') | |
string = string.replace(a, b'ae') | |
string = string.replace(A, b'Ae') | |
string = string.replace(o, b'oe') | |
string = string.replace(O, b'Oe') | |
string = string.replace(ss, b'ss') | |
string = string.decode('utf-8') | |
return string |
@ad1c1337, you are absolutely right. I modified the original snippet to include uppercase Umlauts. Dankeschoen! ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uppercase Umlaute are missing