gpt4 book ai didi

Delphi - 字节数组[0..693] - 转 B64 编码字符串

转载 作者:行者123 更新时间:2023-12-03 15:46:43 25 4
gpt4 key购买 nike

我的代码中有一个声明的变量,如下所示:

Var
VarName:Array[0..693] of Byte = ( and my array here );

我使用了 EncdDecd..

我希望使用 EncdDecd.pas 中的 EncodeBase64 函数将此字节数组编码为 Base64 字符串

但我不确定如何将其返回为一个漂亮且漂亮的 b64 字符串,该字符串可以使用 DecodeBase64 直接转换回字节数组...

我尝试了几种不同的方法..

Var Res:PWideChar;
begin
StringToWideChar(EncodeBase64(@VarName, 693), Res, 693);
ClipBoard.SetTextBuf(Res);
end;

该代码存在访问冲突...

还尝试过:

begin
ClipBoard.SetTextBuf(PWideChar(EncodeBase64(@VarName, 693)));
end;

返回一个充满扭曲中文符号的字符串......

任何有关返回此字符串的帮助将不胜感激..

谢谢!

最佳答案

函数声明为

function  DecodeBase64(const Input: AnsiString): TBytes;
function EncodeBase64(const Input: Pointer; Size: Integer): AnsiString;

所以在 Unicode Delphi 中你所需要的就是将 AnsiString 转换为字符串,

var S: string;

begin
S:= string(EncodeBase64(@VarName, 693));
..

要解码 S,您应该将其转换为 AnsiString:

var B: TBytes;

begin
B:= DecodeBase64(AnsiString(S));
..

关于Delphi - 字节数组[0..693] - 转 B64 编码字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12225505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com