在没有特殊字符的情况下将字符串编码为Android中的Base64? [英] Encode string to Base64 in android without special character?

查看:699
本文介绍了在没有特殊字符的情况下将字符串编码为Android中的Base64?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Base64中编码字符串数据.我正在使用此代码:

I am trying to encode the string data in Base64. I am using this code :

Byte[] url_base64=repl.getBytes("UTF-8");
String con_base64=Base64.encodeToString(url_base64, Base64.NO_WRAP);

通过此代码,我得到了特殊字符,例如("/","\","\ n")等.如何在android中以base64编码忽略这些特殊字符.

Via this code i am getting special characters like ("/","\","\n") etc. How to ignore these special characters in base64 encoding in android.

如果您有任何想法请帮助我.

Please help me if you have any idea about it.

推荐答案

不确定这是否是您想要的,但是

Not sure if this is what you want, but

Base64.encodeToString(url_base64, Base64.NO_WRAP | Base64.URL_SAFE);

将"\"替换为"_"

will replace "\" with "_"

这篇关于在没有特殊字符的情况下将字符串编码为Android中的Base64?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆