常见的三种中文内码转换
2006-02-21 09:19
441 查看
//大五码->GBK
function BIG52GBK(Value: string): string;
var
iLength, iReturn: Integer;
sTmp: PWideChar;
sDest: PChar;
DefChar: Char;
begin
Result := '';
if Value = '' then exit;
iLength := MultiByteToWideChar(950, 0, PChar(Value), -1, nil, 0);
GetMem(sTmp, (iLength+1)*SizeOf(WideChar));
ZeroMemory(sTmp, (iLength+1)*SizeOf(WideChar));
//950 ANSI/OEM - Traditional Chinese (Taiwan; Hong Kong SAR, PRC)
MultiByteToWideChar(950, 0, PChar(Value), Length(Value),
sTmp, iLength+1);
DefChar := '?';
iReturn := WideCharToMultiByte(936, 0, sTmp, -1, nil, 0, @DefChar, nil);
GetMem(sDest, iReturn);
ZeroMemory(sDest, iReturn);
WideCharToMultiByte(936, 0, sTmp, -1, sDest, iReturn, @DefChar, nil);
Result := StrPas(sDest);
FreeMem(sTmp);
FreeMem(sDest);
end;
//GBK->大五码
function GBK2BIG5(Value: string): string;
var
iLength, iReturn: Integer;
sTmp: PWideChar;
sDest: PChar;
DefChar: Char;
begin
Result := '';
if Value = '' then exit;
iLength := MultiByteToWideChar(936, 0, PChar(Value), -1, nil, 0);
GetMem(sTmp, (iLength+1)*SizeOf(WideChar));
ZeroMemory(sTmp, (iLength+1)*SizeOf(WideChar));
MultiByteToWideChar(936, 0, PChar(Value), Length(Value),
sTmp, iLength+1);
DefChar := '?';
iReturn := WideCharToMultiByte(950, 0, sTmp, -1, nil, 0, @DefChar, nil);
GetMem(sDest, iReturn);
ZeroMemory(sDest, iReturn);
WideCharToMultiByte(950, 0, sTmp, -1, sDest, iReturn, @DefChar, nil);
Result := StrPas(sDest);
FreeMem(sTmp);
FreeMem(sDest);
end;
function MAKELANGID(usPrimaryLanguage, usSubLanguage: WORD): WORD;
begin
Result := (usSubLanguage shl 10) or usPrimaryLanguage;
end;
function MAKELCID(wLanguageID: WORD; wSortID: WORD = SORT_DEFAULT): LCID;
begin
Result := MakeLong(wLanguageID, wSortID);
end;
//GB2312->GBK
function GB2GBK(Value: string): string;
var
iLength: Integer;
sTmp: PChar;
begin
iLength := Length(Value);
GetMem(sTmp, iLength+1);
LCMapString(MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),
SORT_CHINESE_PRC),
LCMAP_TRADITIONAL_CHINESE, PChar(Value),
iLength+1, sTmp, iLength+1);
Result :=StrPas(sTmp);
FreeMem(sTmp);
end;
//GBK->GB2312
function GBK2GB(Value: string): string;
var
iLength: Integer;
sTmp: PChar;
begin
iLength := Length(Value);
GetMem(sTmp, iLength+1);
LCMapString(MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),
SORT_CHINESE_BIG5),
LCMAP_SIMPLIFIED_CHINESE, PChar(Value),
iLength+1, sTmp, iLength+1);
Result :=StrPas(sTmp);
FreeMem(sTmp);
end;
function BIG52GBK(Value: string): string;
var
iLength, iReturn: Integer;
sTmp: PWideChar;
sDest: PChar;
DefChar: Char;
begin
Result := '';
if Value = '' then exit;
iLength := MultiByteToWideChar(950, 0, PChar(Value), -1, nil, 0);
GetMem(sTmp, (iLength+1)*SizeOf(WideChar));
ZeroMemory(sTmp, (iLength+1)*SizeOf(WideChar));
//950 ANSI/OEM - Traditional Chinese (Taiwan; Hong Kong SAR, PRC)
MultiByteToWideChar(950, 0, PChar(Value), Length(Value),
sTmp, iLength+1);
DefChar := '?';
iReturn := WideCharToMultiByte(936, 0, sTmp, -1, nil, 0, @DefChar, nil);
GetMem(sDest, iReturn);
ZeroMemory(sDest, iReturn);
WideCharToMultiByte(936, 0, sTmp, -1, sDest, iReturn, @DefChar, nil);
Result := StrPas(sDest);
FreeMem(sTmp);
FreeMem(sDest);
end;
//GBK->大五码
function GBK2BIG5(Value: string): string;
var
iLength, iReturn: Integer;
sTmp: PWideChar;
sDest: PChar;
DefChar: Char;
begin
Result := '';
if Value = '' then exit;
iLength := MultiByteToWideChar(936, 0, PChar(Value), -1, nil, 0);
GetMem(sTmp, (iLength+1)*SizeOf(WideChar));
ZeroMemory(sTmp, (iLength+1)*SizeOf(WideChar));
MultiByteToWideChar(936, 0, PChar(Value), Length(Value),
sTmp, iLength+1);
DefChar := '?';
iReturn := WideCharToMultiByte(950, 0, sTmp, -1, nil, 0, @DefChar, nil);
GetMem(sDest, iReturn);
ZeroMemory(sDest, iReturn);
WideCharToMultiByte(950, 0, sTmp, -1, sDest, iReturn, @DefChar, nil);
Result := StrPas(sDest);
FreeMem(sTmp);
FreeMem(sDest);
end;
function MAKELANGID(usPrimaryLanguage, usSubLanguage: WORD): WORD;
begin
Result := (usSubLanguage shl 10) or usPrimaryLanguage;
end;
function MAKELCID(wLanguageID: WORD; wSortID: WORD = SORT_DEFAULT): LCID;
begin
Result := MakeLong(wLanguageID, wSortID);
end;
//GB2312->GBK
function GB2GBK(Value: string): string;
var
iLength: Integer;
sTmp: PChar;
begin
iLength := Length(Value);
GetMem(sTmp, iLength+1);
LCMapString(MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),
SORT_CHINESE_PRC),
LCMAP_TRADITIONAL_CHINESE, PChar(Value),
iLength+1, sTmp, iLength+1);
Result :=StrPas(sTmp);
FreeMem(sTmp);
end;
//GBK->GB2312
function GBK2GB(Value: string): string;
var
iLength: Integer;
sTmp: PChar;
begin
iLength := Length(Value);
GetMem(sTmp, iLength+1);
LCMapString(MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),
SORT_CHINESE_BIG5),
LCMAP_SIMPLIFIED_CHINESE, PChar(Value),
iLength+1, sTmp, iLength+1);
Result :=StrPas(sTmp);
FreeMem(sTmp);
end;
相关文章推荐
- 常见的三种中文内码转换代码
- 三种常见中文内码的转换方法!
- 三种常见中文内码的转换方法
- 三种常见中文内码的转换方法
- VC中三种常见中文内码的转换方法(GB2312/GBK/BIG5)
- 用C语言实现常见的三种中文内码转换
- 用C语言实现常见的三种中文内码转换
- 三种常见中文内码的转换方法
- C++常见的三种中文内码转换代码
- VC中三种常见中文内码的转换方法
- 三种常见中文内码的转换方法
- 【转天极网文章】VC中三种常见中文内码的转换方法
- 常见的三种中文内码转换代码
- 用C语言实现常见的三种中文内码转换
- 三种常见中文内码的转换方法
- VC中三种常见中文内码的转换方法(GB2312/GBK/BIG5)
- 三种常见中文内码的转换方法
- VC中三种常见中文内码的转换方法
- 用C语言实现常见的三种中文内码转换
- 三种常见中文内码的转换方法