zoukankan      html  css  js  c++  java
  • ansi字符串和utf8字符串之间相互转换

    ansi字符串和utf8字符串之间相互转换

    unit AnsiStringTools;
    
    interface
    
    uses
      SysUtils;
    
    
    
    type
      {$if CompilerVersion <= 18.5}
         TBytes = array of Byte;
      {$ifend}
      TAnsiStringTools = class(TObject)
      public
        /// <summary>
        /// ansi字符串转utf8 bytes
        /// </summary>
        /// <param name="v">ansi字符串</param>
        /// <returns>utf8 bytes</returns>
        class function ansiString2Utf8Bytes(v:AnsiString): TBytes;
        /// <summary>
        /// utf8字符串转ansi字符串
        /// </summary>
        /// <param name="pvData"></param>
        /// <returns>ansi字符串</returns>
        class function Utf8AnsiString2AnsiString(pvData:AnsiString): AnsiString;
        /// <summary>
        /// uft8 bytes转ansi字符串
        /// </summary>
        /// <param name="pvData">uft8 bytes</param>
        /// <returns>ansi字符串</returns>
        class function Utf8Bytes2AnsiString(pvData: TBytes): AnsiString;
      end;
    
    implementation
    
    class function TAnsiStringTools.ansiString2Utf8Bytes(v:AnsiString): TBytes;
    var
      lvTemp:AnsiString;
    begin
      lvTemp := AnsiToUtf8(v);
      SetLength(Result, Length(lvTemp));
      Move(lvTemp[1], Result[0],  Length(lvTemp));
    end;
    
    class function TAnsiStringTools.Utf8AnsiString2AnsiString(pvData:AnsiString):
        AnsiString;
    begin
      Result := Utf8ToAnsi(pvData);
    end;
    
    class function TAnsiStringTools.Utf8Bytes2AnsiString(pvData: TBytes):
        AnsiString;
    var
      lvTemp:AnsiString;
    begin
      SetLength(lvTemp, Length(pvData));
      Move(pvData[0], lvTemp[1],  Length(pvData));
      Result := Utf8ToAnsi(lvTemp);
    end;
    
    end.
    

      

  • 相关阅读:
    java 算法最长连续递增子序列
    java 算法最长连续递增序列
    最大连续子数组和(Java)
    mysql时间序列与窗口函数
    CSS控制br高度
    小知识随手记(九):兄弟选择器(~和+)区别
    VUE组件递归实现自定义目录及拖拽效果
    VUE的插件解析
    VUE的mixin混入解析
    VUE高阶组件解析
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/12262503.html
Copyright © 2011-2022 走看看