汉字转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;
}