如何使用 iOS SDK 将 NSString 转换为引用的可打印形式的 UTF?
我需要将字符串(可能包含非拉丁字符)转换为 UTF-8,并在 引用中进一步编码-可打印表格。
例如,我有一个字符串,例如“привет”,我需要将其转换为“=D0=BF=D1=80.......”之类的东西。
有人可以帮助我吗?
I need to convert a string (probably with non latin characters) to UTF-8, further encoded in a quoted-printable form.
For example I have a string, e.g "привет" and I need to convert it to "=D0=BF=D1=80......." something like that.
Can somebody help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这与 安东的回答,只是短得多:
This is pretty much the same thing as Anton's answer, just a lot shorter:
好吧,我不会遵循这种编码的所有规范。假设您没有尾随空格、换行符和其他不好的东西,这里是您需要的代码:
对于 привет 它给出 =D0=BF=D1=80=D0=B8 =D0=B2=D0=B5=D1=82
Well, I won't follow all the specs of this encoding. Assuming that you don't have tailing whitespaces, newline character and other bad stuff, here is the code you need:
For привет it gives =D0=BF=D1=80=D0=B8=D0=B2=D0=B5=D1=82
上面的答案确实有效,但它们对整个字符串进行编码。这通常不是您想要的,特别是当您使用此代码进行撰写电子邮件之类的操作时。
您实际上可能需要的是一种在 QP 中仅对那些非 ASCII 字符进行编码的方法。
输入:
只需将低音(即整个低音)放入 Bass-o-matic。
输出(简单):
<代码>=53=69=6D=70=6C=79=20=70=6C=61=63=65=20=74=68=65=20=62=61=73=73=E2=80= 94=74=68=61=74=E2=80=99=73=20=74=68=65 =20=77=68=6F=6C=65=20=62=61=73=73=E2=80=94=69=6E=74=6F=20=74=68=65=20=42=61 =73=73=2D=6F=2D=6D=61=74=69=63=2E
输出(改进):
只需将 bass=E2=80=94that=E2=80=99s 整个 bass=E2=80=94 放入 Bass-o-matic。
更像这样
:(基于这个答案构建,用于解码来自本斯尼德)
The above answers do work, but they encode the whole string. Which isn't usually what you'd want, particularly if you're using this code for something like composing an email.
What you're actually likely after is a method to encode only those non-ascii characters in QP.
Input:
Simply place the bass—that’s the whole bass—into the Bass-o-matic.
Output (naiive):
=53=69=6D=70=6C=79=20=70=6C=61=63=65=20=74=68=65=20=62=61=73=73=E2=80=94=74=68=61=74=E2=80=99=73=20=74=68=65=20=77=68=6F=6C=65=20=62=61=73=73=E2=80=94=69=6E=74=6F=20=74=68=65=20=42=61=73=73=2D=6F=2D=6D=61=74=69=63=2E
Output (improved):
Simply place the bass=E2=80=94that=E2=80=99s the whole bass=E2=80=94into the Bass-o-matic.
Something more like this:
(builds off of this answer for decoding QP strings from bensnider)
尝试
[NSString stringWithUTF8String:yourString];
Try
[NSString stringWithUTF8String:yourString];
使用这个 -
现在打印“finalEncodedString”,它现在是 UTF8 编码的字符串。
Use This -
Now print the 'finalEncodedString', it's UTF8 encoded string now.