求简繁内码转换控件 ( 积分: 100 )

  • 主题发起人 主题发起人 wufo
  • 开始时间 开始时间
W

wufo

Unregistered / Unconfirmed
GUEST, unregistred user!
现在公司的一个小软件需要给台湾人用,想实现简繁内码转换,传说坛子里的大侠有控件,特来借用一下。还请各路大侠帮忙!
 
C语言写的,要不要?

int HexToInt(int x)
{
int t = x;
if (x >= '0' && x <= '9')
{
t -= '0';
}
else if (t >= 'a' && t <= 'f')
{
t -= 'a' - 10;
}
else if (t >= 'A' && t <= 'F')
{
t -= 'A' - 10;
}
return t;
}

void Decode(char *dest,const char *pData)
{
char c0,c1, h[100];
int i,j,num;
unsigned char *q = (unsigned char *)pData;

i = j = num = 0;

//if (pData == NULL) return NULL;
while (*q)
{
if (pData == '+')
{
h[j] = ' ';
q++;
i++;
j++;
}
else if (pData == '%')
{
c0 = pData[i+1];
c1 = pData[i+2];
num = HexToInt(c0)*16+ HexToInt(c1);
h[j] = num;
q++;
i+=3;
j++;
}
else
{
h[j] = pData;
q++;
i++;
j++;
}
}
strcpy(dest, h);
//printf("%s", h);
}
 
没控件,有函数
function GetSysDefaultLg: TLanguage;
var
LangID: Integer;
begin
Result := tNone;
LangID := GetSystemDefaultLangID;
if LangID = ((SUBLANG_ENGLISH_US shl 10) or LANG_ENGLISH) then
Result := tEnglish //美国英语
else if LangID = ((SUBLANG_CHINESE_SIMPLIFIED shl 10) or LANG_CHINESE) then
Result := tGBChs //简体中文
else if LangID = ((SUBLANG_CHINESE_TRADITIONAL shl 10) or LANG_CHINESE) then
Result := tBig5; //繁体中文
end;

function Big5ToGB(BIG5Str: string): AnsiString;
{进行big5转GB内码}
var
Len: Integer;
pBIG5Char: PChar;
pGBCHSChar: PChar;
pGBCHTChar: PChar;
pUniCodeChar: PWideChar;
begin
//String -> PChar
pBIG5Char := PChar(BIG5Str);
Len := MultiByteToWideChar(950, 0, pBIG5Char, -1, nil, 0);
GetMem(pUniCodeChar, Len * 2);
ZeroMemory(pUniCodeChar, Len * 2);
//Big5 -> UniCode
MultiByteToWideChar(950, 0, pBIG5Char, -1, pUniCodeChar, Len);
Len := WideCharToMultiByte(936, 0, pUniCodeChar, -1, nil, 0, nil, nil);
GetMem(pGBCHTChar, Len * 2);
GetMem(pGBCHSChar, Len * 2);
ZeroMemory(pGBCHTChar, Len * 2);
ZeroMemory(pGBCHSChar, Len * 2);
//UniCode->GB CHT
WideCharToMultiByte(936, 0, pUniCodeChar, -1, pGBCHTChar, Len, nil, nil);
//GB CHT -> GB CHS
LCMapString($804, LCMAP_SIMPLIFIED_CHINESE, pGBCHTChar, -1, pGBCHSChar, Len);
Result := string(pGBCHSChar);
FreeMem(pGBCHTChar);
FreeMem(pGBCHSChar);
FreeMem(pUniCodeChar);
end;

function GBToBig5(GBStr: string): AnsiString;
{进行GB转BIG5内码}
var
Len: Integer;
pGBCHTChar: PChar;
pGBCHSChar: PChar;
pUniCodeChar: PWideChar;
pBIG5Char: PChar;
begin
pGBCHSChar := PChar(GBStr);
Len := MultiByteToWideChar(936, 0, pGBCHSChar, -1, nil, 0);
GetMem(pGBCHTChar, Len * 2 + 1);
ZeroMemory(pGBCHTChar, Len * 2 + 1);
//GB CHS -> GB CHT
LCMapString($804, LCMAP_TRADITIONAL_CHINESE, pGBCHSChar, -1, pGBCHTChar, Len * 2);
GetMem(pUniCodeChar, Len * 2);
ZeroMemory(pUniCodeChar, Len * 2);
//GB CHT -> UniCode
MultiByteToWideChar(936, 0, pGBCHTChar, -1, pUniCodeChar, Len * 2);
Len := WideCharToMultiByte(950, 0, pUniCodeChar, -1, nil, 0, nil, nil);
GetMem(pBIG5Char, Len);
ZeroMemory(pBIG5Char, Len);
//UniCode -> Big5
WideCharToMultiByte(950, 0, pUniCodeChar, -1, pBIG5Char, Len, nil, nil);
Result := string(pBIG5Char);
FreeMem(pBIG5Char);
FreeMem(pGBCHTChar);
FreeMem(pUniCodeChar);
end;

function GBChtToChs(GBStr: string): AnsiString;
{进行GBK繁体转简体}
var
Len: Integer;
pGBCHTChar: PChar;
pGBCHSChar: PChar;
begin
pGBCHTChar := PChar(GBStr);
Len := MultiByteToWideChar(936, 0, pGBCHTChar, -1, nil, 0);
GetMem(pGBCHSChar, Len * 2 + 1);
ZeroMemory(pGBCHSChar, Len * 2 + 1);
//GB CHS -> GB CHT
LCMapString($804, LCMAP_SIMPLIFIED_CHINESE, pGBCHTChar, -1, pGBCHSChar, Len * 2);
Result := string(pGBChsChar);
//FreeMem(pGBCHTChar);
FreeMem(pGBCHSChar);
end;

function GBChsToCht(GBStr: string): AnsiString;
{进行GBK简体转繁体}
var
Len: Integer;
pGBCHTChar: PChar;
pGBCHSChar: PChar;
begin
pGBCHSChar := PChar(GBStr);
Len := MultiByteToWideChar(936, 0, pGBCHSChar, -1, nil, 0);
GetMem(pGBCHTChar, Len * 2 + 1);
ZeroMemory(pGBCHTChar, Len * 2 + 1);
//GB CHS -> GB CHT
LCMapString($804, LCMAP_TRADITIONAL_CHINESE, pGBCHSChar, -1, pGBCHTChar, Len * 2);
Result := string(pGBCHTChar);
FreeMem(pGBCHTChar);
//FreeMem(pGBCHSChar);
end;
 
两年前写的世界上最简单最完善的简繁体相互转换SQL函数 ,源代码

http://hi.baidu.com/earthsearch/blog/item/b4f3e936b0a480310a55a908.html
 
nicai_wgl:
TLanguage如何定义?
MultiByteToWideChar 在哪儿定义的,要Uses哪些单元?
 
两年前写的世界上最简单最完善的简繁体相互转换SQL函数 ,源代码

http://hi.baidu.com/earthsearch/blog/item/b4f3e936b0a480310a55a908.html

给分吧,别不识货!
 
dcms:
我没说清楚,我的不是数据库程序,是应用程序,和数据库不相关,谢谢
 
谢谢两们,问题已解决了。
 
uses
Windows, Forms, Classes, StdCtrls, Menus, Controls, ExtCtrls;

type
TLanguage = (
tNone,
tEnglish,
tGBChs,
tBig5,
tGBCht
);
 
多人接受答案了。
 
請問樓主,是怎麼解決的?
能否貼出解決方法?謝謝先
 
我想此软件可以帮助你 applocale
不用修改程序那么麻烦
 
后退
顶部