多行编码和解码 [英] Encoding and decoding with more lines

查看:72
本文介绍了多行编码和解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我之前也遇到过类似的问题,所以很抱歉如果我应该只在这里写而不是创建新主题. 您在有关从文件进行编码和解码以及将其归档的问题中向我提出了建议:

Hi,
I haved similar problem before so sorry if I should just write it there instead of creating new topic.
You adviced me in my question about encoding and decoding from file and to file this:

public static string encode(string text)
{
    byte[] mybyte = System.Text.Encoding.UTF8.GetBytes(text);
    string returntext = System.Convert.ToBase64String(mybyte);
    return returntext;
}

public static string decode(string text)
{
    byte[] mybyte = System.Convert.FromBase64String(text);
    string returntext = System.Text.Encoding.UTF8.GetString(mybyte);
    return returntext;
}


(虽然有人不建议使用UTF-8:D推荐给我),但是现在看来,当我想用​​多于两行的文本文件进行编码/解码时,它似乎不起作用.该代码不好吗?


(while someone unrecommended me using UTF-8 :D)but now it seems it doesn''t work when I want to encode/decode from text file with more than two lines. Is that code bad?

推荐答案

这取决于正在读取文件并调用您在此问题中发布的代码的代码.

我能想到它仅适用于文件的一行的唯一原因是因为您仅读取了原始文件的一行和/或您读取了多行(并获得了字符串数组),并且只传递了第一个字符串
That depends on the code that is reading the file and calling the code you posted in this question.

The only reasons I can think of that it only works with one line of your file is because you only read one line of the original file and/or you read multiple lines (and got an array of strings) and you only passed the first string to this code.


好,对不起.好像问题出在调用解密时输入变量错误.感谢您的帮助
Ok, sorry guys. Seems like the problem was bad input variable in calling decryption.. well this is embarassing. Thanks for your helping


这篇关于多行编码和解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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