1.2.5. NFKD¶
参见其他3种实现就明白本实现了
示例¶
代码:
import unicodedata
# 示例字符串
s1 = 'café'
s2 = 'cafe\u0301' # 已经是NFD形式
s3 = '①②③' # 包含兼容性字符
# 使用NFKD规范化
normalized_s1 = unicodedata.normalize('NFKD', s1)
normalized_s2 = unicodedata.normalize('NFKD', s2)
normalized_s3 = unicodedata.normalize('NFKD', s3)
print(normalized_s1) # 输出: cafe
print(normalized_s2) # 输出: cafe
print(normalized_s3) # 输出: 123
# 比较规范化后的字符串
print(normalized_s1 == normalized_s2) # 输出: True