zoukankan      html  css  js  c++  java
  • 汉字转UNICODE?

    Function Str_Gb2UniCode(text:String):String;
    var
     i,j,len: integer;
     cur: integer;
     t: String;
     ws: widestring;
    begin
     Result:='';
     ws:=text;
     len:=length(ws);
     i:=1;
     j:=0;
     while i<=len do
     begin
       cur:=ord(ws[i]);
       FmtStr(t,'%4.4X',[cur]);//BCD转换
       Result:=Result+t;
       inc(i);
        j:=(j+1)mod 7;//移位计数器达7要特殊处理
      end;
    end;

    //test

     Caption := Str_Gb2UniCode('您好');

    #include <stdio.h>
    #include <windows.h>

    void Encode2(IN wchar_t * pWsString, OUT char *ppResult)
    {
       for(unsigned int dwLoop = 0; dwLoop < wcslen(pWsString); dwLoop++)
       {
       sprintf(ppResult, "%04X", pWsString[dwLoop]);
       ppResult += 4;
       }
    }

    int main()
    {
       wchar_t wcDbg[1024];
       wcscpy(wcDbg, L"您好"); //测试数据
       char oResult[1024 * 4];        //这个保存结果   
       ZeroMemory(&oResult, sizeof(oResult));
       Encode2(wcDbg, oResult);
       printf("%s\n", oResult);
       return 0;
    }

  • 相关阅读:
    UVALive4727:jump
    UVALive
    UVA11795 Mega Man's Mission
    UVA4731:Cellular Network
    UVA11404:Palindromic Subsequence
    设计思路
    阅读计划
    上课未完成代码原因
    《人月神话》读后感
    《软件工程》第十一章总结
  • 原文地址:https://www.cnblogs.com/chengxin1982/p/1403744.html
Copyright © 2011-2022 走看看