Delphi-UTF8转GBK
<p> </p><p>/////////////////////////////////////////////<br>function TXml.getValue(str: string): string;//传入的UTF8字符串<br>var<br>s: string;<br>begin<br>if FBase64 then<br>begin<br> s := TNetEncoding.Base64.EncodeBytesToString(TEncoding.ANSI.GetBytes(str));<br> s := s.Replace(#13#10,'');<br> Result := s;//输出UTF8转GBK后的base64字符串<br>end<br>else<br> Result := str;<br>end;<br>///////////////////////////////////////////////////////<br>function AnsiBase64Encode(s : string) : string;//传入的UTF8字符串<br>var base64 : TIdEncoderMIME;<br> tmpBytes : TBytes;<br>begin<br>base64 := TIdEncoderMIME.Create(nil);<br>try<br> base64.FillChar := '=';<br> tmpBytes := TEncoding.ANSI.GetBytes(s);<br> Result := base64.EncodeBytes(TIdBytes(tmpBytes)); //Delphi默认加密会78个字符进行换行,后者过滤掉换行//Result := base64.EncodeBytes(TIdBytes(tmpBytes)).Replace(sLineBreak, '', );<br>finally<br> base64.Free;<br>end;<br>end;</p>
<p><br>function TXml.getValue(str: string): string;//传入的UTF8字符串<br>var<br>s: string;<br>begin<br>if FBase64 then<br>begin<br> s := AnsiBase64Encode(str);<br> s := s.Replace(#13#10,'');<br> Result := s;//输出UTF8转GBK后的base64字符串<br>end<br>else<br> Result := str;<br>end;</p>
<p> </p>
<div id="qb-sougou-search" style="display: none; opacity: 0">
<p>翻译</p>
<p class="last-btn">搜索</p>
<p class="last-btn">复制</p>
<iframe></iframe></div>
</div>
<div id="MySignature" role="contentinfo">
<div id="AllanboltSignature">
<div>作者:疯狂Delphi</div>
<div>出处:https://www.cnblogs.com/FKdelphi/</div>
<div>本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.</div>
</div>
<div class="div_masklayer" id="div_masklayer"></div>
<div class="div_popup" id="Div_popup">
<p class="mid">欢迎关注我,一起进步!扫描下方二维码即可加我</p>
<img class="img_zfb" id="img_zfb" width="150" src="https://images.cnblogs.com/cnblogs_com/FKdelphi/1101510/o_251208113944_QQ.png">
<img class="img_zfb" id="img_zfb" width="150" src="https://images.cnblogs.com/cnblogs_com/FKdelphi/1101510/o_251208115029_WX.png">
</div><br><br>
来源:https://www.cnblogs.com/FKdelphi/p/17308356.html
頁:
[1]