UniCode 轉 GB 函數
參考資料:http://hi.baidu.com/3228911/blog/item/a6bd37a3c27883a6cbefd0c0.html
/*
中 文: 請輸入密碼
16進制: /u8ACB/u8F38/u5165/u5BC6/u78BC
10進制: #35531#36664#20837#23494#30908
*/
function TForm1.UniCodeToGB(UStr: String): String;
Var
s1: string;
begin
s1 := UStr;
Result := '';
if pos('/u', s1)> 0 then
begin
//16進制轉換
s1 := StringReplace(s1,'/u','',[rfReplaceAll]);
//
while Length(s1) >= 4 do
begin
Result := Result + WideChar(StrToInt('$'+ s1[1] + s1[2] + s1[3] + s1[4]));
s1 := Copy(s1, 5, MaxInt);
end;
end
else if pos('#', s1)> 0 then
begin
//10進制轉換
s1 := StringReplace(s1,'#','',[rfReplaceAll]);
//
while Length(s1) >= 5 do
begin
Result := Result + WideChar(StrToInt(s1[1] + s1[2] + s1[3] + s1[4] + s1[5]));
s1 := Copy(s1, 6, MaxInt);
end;
end;
//
Result := Result + s1;
end;