-
-
Save anonymous/b225921b98ca864d0dd6 to your computer and use it in GitHub Desktop.
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 str_full_to_half(in_str): | |
""" | |
Adapt from http://www.pythonclub.org/python-scripts/quanjiao-banjiao | |
""" | |
out_str = [] | |
for char in ustring: | |
inside_code = ord(char) | |
if inside_code == 0x3000: | |
inside_code = 0x0020 # space | |
else: | |
inside_code -= 0xfee0 | |
if inside_code < 0x0020 or inside_code > 0x7e: | |
out_str.append(char) | |
out_str.append(chr(inside_code)) | |
return ''.join(out_str) | |
# str_full_to_half(',:') | |
# ',:' | |
# str_full_to_half('、') | |
# ValueError |
def str_full_to_half(in_str):
out_str = []
for char in in_str:
inside_code = ord(char)
if inside_code == 0x3000:
inside_code = 0x0020 # space
else:
inside_code -= 0xfee0
if inside_code < 0x0020 or inside_code > 0x7e:
out_str.append(char)
out_str.append(chr(inside_code))
return ''.join(out_str)
It works!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there:
ustring seems not be defined, can you revised it?thanks a lot!