c# - 使用 GSM-7 和 UCS-2 的 SMS 拆分字符串
问题描述
我想弄清楚如何获取一个可能包含或不包含 unicode(例如表情符号)的字符串,并将其正确拆分为可以通过 SMS 发送的“部分”。我使用多个不同的 SMS API,不能依赖所有这些 API 来连接相同(或正确),所以我宁愿自己负责拆分消息。此外,我想实现某种自动换行,以便当消息被强制拆分时,我不会将一个词切成两半,而是将其推送到下一条短信。
据我了解,SMS 限制为 160 个字符,或者在串联的情况下限制为 153 个,但这严格使用 GSM-7 的 7 位字符,并且在 UCS-2 中添加 unicode 字符会使字符限制显着下降,因为UCS-2 编码字符占用更多字节。因此,计数字符似乎是不可靠的,相反,我需要以某种方式拆分字节而不破坏消息。
我试图弄清楚如何写:
- get bytes of msgBody string
- get encoding type of msgBody, GSM-7 or UCS-2
- get max byte size of that encoding type
- if msgBody byte size = multiple messages, split into parts
- if first part's last character isn't whitespace, push the cut-up word's first half into the next message
- somehow insure that pushing those bytes along doesn't result in the next message being too large
解决方案
推荐阅读
- c# - 如何模拟从 Azure Function 调用的方法?
- xcode - 如何使用 XCode 的 mergetool 解决冲突?
- sql - TypeORM:@JoinTable 三列
- android - 将令牌从一个应用程序发送到另一个应用程序,避免使用意图选择器
- matlab - 如何保持信号simulink matlab的2个峰值
- ruby - 为什么要私有封装私有常量?
- angular - ng build --prod 非常慢
- javascript - 为什么我的 MutationObserver 对象没有断开连接?
- php - 在 WP_Mail 标头中设置“发件人地址”会导致电子邮件进入垃圾邮件
- sql - 强制为左连接返回空值