Skip to content

Instantly share code, notes, and snippets.

@bact
Created July 6, 2019 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bact/9f94c343dfd4ed85bfc026fdc0c18d65 to your computer and use it in GitHub Desktop.
Save bact/9f94c343dfd4ed85bfc026fdc0c18d65 to your computer and use it in GitHub Desktop.
Convert Thai digits to Arabic digits
_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