在Android中如何连接的base64 EN codeD字符串? [英] In Android how to concatenate base64 encoded strings?

查看:174
本文介绍了在Android中如何连接的base64 EN codeD字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我解决这个问题:

我有两个字符串电子邮件ID和密码,如

String name = "xyz@gmail.com";
String pass = "abc";

我的连接code这两个成Base64的字符串,如

String encoded_name = new String(Base64.encode(name.getBytes(), 0));
String encoded_pass = new String(Base64.encode(pass.getBytes(), 0));

我需要连接这两个连接codeD字符串中包含空格

String merge = encoded_name + " " + encoded_pass;

我在控制台中检查该字符串

System.out.print("Concatenate string= " + merge);

但在控制台中我得到的结果在两行像这样

but in console I am getting result in two lines like this

11-18 00:25:29.898: INFO/System.out(1244): Merge= eHl6QGdtYWlsLmNvbQ==
11-18 00:25:29.908: INFO/System.out(1244):  YWJj

这是为什么happing结果是意想不到的,我为什么不打印在一行。请帮我解决这个问题。

Why is this happing the result is unexpected for me why it is not printing in a single line. please help me to solve this.

感谢

推荐答案

您应该使用NO_WRAP标志作为的文档,Base64编码类将不会增加额外的新行。

You should use the NO_WRAP flag as described in the Docs, the Base64 class will not add additional newlines.

NO_WRAP:恩codeR标志位来省略所有行结束符(即输出将在一个长行)

NO_WRAP: Encoder flag bit to omit all line terminators (i.e., the output will be on one long line).

所以,改变你的行为以下内容:

So change your lines to the following:

String encoded_name = new String(Base64.encode(name.getBytes(), Base64.NO_WRAP));
String encoded_pass = new String(Base64.encode(pass.getBytes(), Base64.NO_WRAP));

这将输出以下内容:

11-17 19:16:51.283: INFO/System.out(354): Concatenate string= eHl6QGdtYWlsLmNvbQ== YWJj

这篇关于在Android中如何连接的base64 EN codeD字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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