Created
July 6, 2019 09:44
-
-
Save bact/9f94c343dfd4ed85bfc026fdc0c18d65 to your computer and use it in GitHub Desktop.
Convert Thai digits to Arabic digits
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
_THAI_ARABIC = { | |
"๐": "0", | |
"๑": "1", | |
"๒": "2", | |
"๓": "3", | |
"๔": "4", | |
"๕": "5", | |
"๖": "6", | |
"๗": "7", | |
"๘": "8", | |
"๙": "9", | |
} | |
def thai_digit_to_arabic_digit(text: str) -> str: | |
""" | |
:param str text: Text with Thai digits such as '๑', '๒', '๓' | |
:return: Text with Thai digits being converted to Arabic digits such as '1', '2', '3' | |
""" | |
if not text or not isinstance(text, str): | |
return "" | |
newtext = [] | |
for ch in text: | |
if ch in _THAI_ARABIC: | |
newtext.append(_THAI_ARABIC[ch]) | |
else: | |
newtext.append(ch) | |
return "".join(newtext) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment