【发布时间】:2011-02-28 12:51:50
【问题描述】:
我需要一种算法(最好在 Python 中)将任意字符串转换为仅包含 GSM 字母表中字符的字符串。我需要这个过滤器将字符串作为 SMS:es 中的文本发送。如果可能,该算法还应该用最接近的可编码等效字符替换字符。例子:
>>> gsm_convert('© all rights reserved')
[copyright sign] all rights reserved
# or
C all rights reserved
>>> gsm_convert('––– long dashes –––')
--- long dashes ---
Python 有一些内置算法可以做到这一点,但这些函数也会将输入字符串转换为不正确的 ascii。 GSM 可以处理几个在 ascii 中找不到的字符。
【问题讨论】:
标签: python unicode encoding sms gsm