[英]convert string[] to base64
I am opening a file encoded in base64 and I need to decode it我正在打开一个用 base64 编码的文件,我需要对其进行解码
string[] lines = File.ReadAllLines(open1.FileName);
is there anyway to do this?有没有办法做到这一点? I have tried doing this.
我试过这样做。
string[] lines = File.ReadAllLines(Convert.ToBase64String(open1.FileName));
you question is not clear你的问题不清楚
if you want to convert string[] to array of base64 you can do this :如果你想将 string[] 转换为 base64 数组,你可以这样做:
public static string[] ToBase64(string[] text)
{
var encodedArray = new string[text.Length];
for (var index = 0; index < text.Length; index++)
{
var line = text[index];
var encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(line));
encodedArray[index] = encoded;
}
return encodedArray;
}
this return your array with each line encoded in base64.这将返回您的数组,其中每一行都以 base64 编码。 and to reverse it :
并扭转它:
public static string[] ToString(string[] encodedString)
{
var decodedArray = new string[encodedString.Length];
for (var i = 0; i < encodedString.Length; i++)
{
var line = encodedString[i];
var decoded = Convert.FromBase64String(line);
decodedArray[i] = Encoding.UTF8.GetString(decoded);
}
return decodedArray;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.