Android 中是否有使用完整百分比编码对字符串进行编码/解码的快速函数?
我想在 Android 应用程序中对某些字符串操作使用百分比值编码/解码。我不想使用 URI 编码/解码函数对,因为我想对每个字符进行编码,而不仅仅是在对 URI 进行编码以发出 Web 请求时编码的字符。 Android 库或 Java 库中有内置函数可以做到这一点吗?
——罗施勒
I want to use percent value encoding/decoding for some string operations in my Android application. I don't want to use a URI encode/decode function pair because I want to encode every character, not just the ones that are encoded when encoding URI's for making web requests. Are there any built-in functions in the Android libraries or Java libraries that can do this?
-- roschler
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
API 中没有内置任何内容可以直接执行此操作,但它非常简单。最好使用特定的字符编码(如 UTF-8)将字符转换为字节。这应该可以解决编码问题:
哦,是的,您还要求解码:
There's nothing built in to the API to do this directly, but it's pretty simple. It's better to use a specific character encoding (like UTF-8) to convert characters to bytes. This should do the trick for encoding:
Oh yes, you asked for decoding as well:
这是非常简单的,并且不需要库函数:
This is pretty trivial, and doesn't need library functions: