标签:== bsp nbsp awb 验证 test kaa send dll
procedure TForm1.Button1Click(Sender: TObject); var s,s1:string; arr,arr1:TArray<Byte>; begin s := ‘sjddllkd百增值是38(#(8<>Ijj*王山儿*‘; //内存复制 s到arr再到s1 SetLength(arr,s.Length*2);//arr.Length:=56 CopyMemory(arr,@s[1],s.Length*2); SetLength(s1,s.Length); CopyMemory(@s1[1],arr,s.Length*2); ShowMessage(s1); //string编码得到字节数组 arr1:= TEncoding.UTF8.GetBytes(s);//arr1.Length:=46 s1 := TEncoding.UTF8.GetString(arr1); ShowMessage(s1); //base64测试 内存编码 s:=TNetEncoding.Base64.EncodeBytesToString(arr); //s:=‘cwBqAGQAZABsAGwAawBkAH52nlg8UC9mMwA4AAj/IwAI/zgAPAA+AEkAagBqACoAi3NxXD9RKgA=‘ ShowMessage(s); SetLength(arr,0); arr := TNetEncoding.Base64.DecodeStringToBytes(s); CopyMemory(@s1[1],arr,Length(arr)); ShowMessage(s1); //base64测试 string编码 s1 := TNetEncoding.Base64.Encode(s1); //s1:=‘c2pkZGxsa2Tnmb7lop7lgLzmmK8zOO+8iCPvvIg4PD5Jamoq546L5bGx5YS/Kg==‘ ShowMessage(s1); s1 := TNetEncoding.Base64.Decode(s1); ShowMessage(s1); end;
结论:
1.字符串转字节数组使用utf8编码转换节省空间;
2.TNetEncoding.Base64直接编码字串实际使用的就是utf8的字节数组(查看原码);
3.测试比较简单,仅验证理论知识。
标签:== bsp nbsp awb 验证 test kaa send dll
原文地址:http://www.cnblogs.com/wangsaner/p/7149997.html