import re
def chinese_to_unicode(text):
# 匹配中文字符
def to_unicode(match):
return ''.join(f'\\u{ord(char):04x}' for char in match.group())
# 正则匹配中文字符的范围
return re.sub(r'[\u4e00-\u9fff]', to_unicode, text)
def unicode_to_chinese(text):
# 匹配Unicode编码
def to_chinese(match):
return chr(int(match.group(1), 16))
# 正则匹配Unicode格式的字符串(如\u4e00)
return re.sub(r'\\u([0-9a-fA-F]{4})', to_chinese, text)
unicode中文互转
于 2024-08-19 14:35:00 首次发布
1867

被折叠的 条评论
为什么被折叠?



