帮忙解决了这个问题,立马500奉上。谢谢从第二代身份证里读取的姓名怎么转也转不了繁体,很是烦啊。。一连几在,用google和百度把整个网络搜了个遍,也没有找到一种可以将姓名转成繁体的并能在繁体XP中正常显示的方法
如: 韩浩梁 三个字,
在简体xp中转成繁体可以正常显示成 '韓浩梁'
但是在繁体XP中确只能显示成 '?浩梁'韓 显示成了?号,
还有一其它一些字,如某某县的县,好像是只要有对应繁体字的都不能显示出来
我用的是DELPHI 2009.但是 。
我直接用键盘输入 韩浩梁 三个字再转成繁体,
不管是在简体XP,还是繁体XP都是可以正常显示成繁体 '韓浩梁' 的。。为什么呢???我试了很多种转换函数。都不行。线索:考虑从身份证读出来的字符编码格式,我上网找了,好像是什么GB13000的。
如: 韩浩梁 三个字,
在简体xp中转成繁体可以正常显示成 '韓浩梁'
但是在繁体XP中确只能显示成 '?浩梁'韓 显示成了?号,
还有一其它一些字,如某某县的县,好像是只要有对应繁体字的都不能显示出来
我用的是DELPHI 2009.但是 。
我直接用键盘输入 韩浩梁 三个字再转成繁体,
不管是在简体XP,还是繁体XP都是可以正常显示成繁体 '韓浩梁' 的。。为什么呢???我试了很多种转换函数。都不行。线索:考虑从身份证读出来的字符编码格式,我上网找了,好像是什么GB13000的。
解决方案 »
- 请教如何在DELPHI中调用matlab文件?
- 为什么我的线程执行起来那么困难 甚至象死机了一样啊:
- 请问用Delphi+lotus编写OA有这可能吗?
- 急求:一个简单的留言板代码
- delphi中memo是什么组件?
- 2个问题,50fen
- 请各位大侠出手相助:是否有控件可放Word表格
- 请问:谁知道那里有能将dateset的数据直接倒到excel的控件或者有没有什么比较好的方法除了先读出记录然后一条条的在excel控件的表格里写入还有其他方法吗?
- 问一个全文检索的问题
- 急急急!如何锁屏?
- 这个错误是。。?operator not applicable to this operand type
- ★★★ 高分求助!我的idHttp为什么不能提交数据到表单? 大哥大姐看看吧
http://topic.csdn.net/t/20050502/14/3980763.html
//---------------------------------------------------------------------------
// 大五码转GBK码:
// い地チ㎝瓣 --> 中華人民共和國
void __fastcall BIG52GBK(char *szBuf)
{
if(!strcmp(szBuf, ""))
return;
int nStrLen = strlen(szBuf);
wchar_t *pws = new wchar_t[nStrLen + 1];
try
{
int nReturn = MultiByteToWideChar(950, 0, szBuf, nStrLen, pws, nStrLen + 1);
BOOL bValue = false;
nReturn = WideCharToMultiByte(936, 0, pws, nReturn, szBuf, nStrLen + 1, "?", &bValue);
szBuf[nReturn] = 0;
}
__finally
{
delete[] pws;
}
}
//---------------------------------------------------------------------------
// GBK转大五码
// 中華人民共和國 --> い地チ㎝瓣
void __fastcall GBK2BIG5(char *szBuf)
{
if(!strcmp(szBuf, ""))
return ;
int nStrLen = strlen(szBuf);
wchar_t *pws = new wchar_t[nStrLen + 1];
try
{
MultiByteToWideChar(936, 0, szBuf, nStrLen, pws, nStrLen + 1);
BOOL bValue = false;
WideCharToMultiByte(950, 0, pws, nStrLen, szBuf, nStrLen + 1, "?", &bValue);
szBuf[nStrLen] = 0;
}
__finally
{
delete[] pws;
}
}
//----------------------------------------------------------------------------
// 抱歉,这个提示又来了,为了防止不负责任的转载者,只好在此留些信息。
// 作者:ccrun(老妖) [email protected]
// 本文转自 C++Builder 研究 - http://www.ccrun.com/article/go.asp?i=634&d=04g63p
//---------------------------------------------------------------------------
// GB2312码转GBK码
// 本文转自 C++Builder研究 - http://www.ccrun.com/article.asp?i=634&d=04g63p
// 中华人民共和国 --> 中華人民共和國
void __fastcall GB2GBK(char *szBuf)
{
if(!strcmp(szBuf, ""))
return;
int nStrLen = strlen(szBuf);
WORD wLCID = MAKELCID(MAKELANGID
(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_PRC);
int nReturn = LCMapString(wLCID, LCMAP_TRADITIONAL_CHINESE, szBuf, nStrLen, NULL, 0);
if(!nReturn)
return;
char *pcBuf = new char[nReturn + 1];
try
{
wLCID = MAKELCID(MAKELANGID
(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_PRC);
LCMapString(wLCID, LCMAP_TRADITIONAL_CHINESE, szBuf, nReturn, pcBuf, nReturn + 1);
strncpy(szBuf, pcBuf, nReturn);
}
__finally
{
delete[] pcBuf;
}
}
//---------------------------------------------------------------------------
// GBK码转GB2312码
// 中華人民共和國 --> 中华人民共和国
void __fastcall GBK2GB(char *szBuf)
{
if(!strcmp(szBuf, ""))
return;
int nStrLen = strlen(szBuf);
WORD wLCID = MAKELCID(MAKELANGID
(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_BIG5);
int nReturn = LCMapString(wLCID, LCMAP_SIMPLIFIED_CHINESE, szBuf, nStrLen, NULL, 0);
if(!nReturn)
return;
char *pcBuf = new char[nReturn + 1];
try
{
wLCID = MAKELCID(MAKELANGID
(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_BIG5);
LCMapString(wLCID, LCMAP_SIMPLIFIED_CHINESE, szBuf, nReturn, pcBuf, nReturn + 1);
strncpy(szBuf, pcBuf, nReturn);
}
__finally
{
delete []pcBuf;
}
}
//---------------------------------------------------------------------------
// 测试代码
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char szBuf[255];
// 从GB2312转到GBK
strcpy(szBuf, Edit1->Text.c_str());
GB2GBK(szBuf);
Edit2->Text = String(szBuf);
// 从GB2312转到BIG5,通过GBK中转
strcpy(szBuf, Edit1->Text.c_str());
GB2GBK(szBuf);
GBK2BIG5(szBuf);
Edit3->Text = String(szBuf);
}注意,请不要使用String类的c_str()作为上述几个函数的传入参数。
// ver 1.01
// By Tom Lee 1997/9/5
// E-Mail Address : [email protected]
// It is Freeware !unit CVCode;interface
function GBtoBIG5(value: string): string;
function BIG5toGB(value: string): string;implementationvar
BIG5Order: array[0..14757] of Word;
GBOrder : array[0..8177] of Word;function GBOffset(value: string): integer;
Var
mHigh, mLow : integer;
mGBK1, mGBK2, mGBK3, mGBK4, mGBK5: integer;
begin Result := -1;
if length(value) >= 2 then
begin
mHigh := ord(value[1]);
mLow := ord(value[2]);
mGBK1 := $34E; //846
mGBK1 := mGBK1 + ($B0 - $A9-1) * ($FE - $A1 + 1);
mGBK2 := $1A70; //6768
mGBK3 := $17E0; //6112
mGBK4 := $2035; //8245
mGBK5 := $C2; //194 if (mHigh in [$A1..$A9]) and (mLow in [$A1..$FE]) then
Result := (mHigh - $A1) * ($FE - $A1 + 1) + (mLow - $A1) else if (mHigh in [$B0..$F7]) and (mLow in [$A1..$FE]) then
Result := mGBK1 +
(mHigh - $B0) * ($FE - $A1 + 1) + (mLow - $A1) else if (mHigh in [$81..$A0]) and (mLow in [$40..$FE]) then
Result := mGBK1 + mGBK2 +
(mHigh - $81) * ($FE - $40 + 1) + (mLow - $40) else if (mHigh in [$AA..$FE]) and (mLow in [$40..$A0]) then
Result := mGBK1 + mGBK2 + mGBK3 +
(mHigh - $AA) * ($A0 - $40 + 1) + (mLow - $40) else if (mHigh in [$A8..$A9]) and (mLow in [$40..$A0]) then
Result := mGBK1 + mGBK2 + mGBK3 + mGBK4 +
(mHigh - $A8) * ($A0 - $40 + 1) + (mLow - $40);
end
end;function BIG5Offset(value: string): integer;
begin
Result := -1;
if length(value) >= 2 then
begin
if (Ord(value[2]) >= 64) and (Ord(value[2]) <= 126) then
Result := (Ord(value[1]) - 161) * 157 + (Ord(value[2]) - 64);
if (Ord(value[2]) >= 161) and (Ord(value[2]) <= 254) then
Result := (Ord(value[1]) - 161) * 157 + 63 + (Ord(value[2]) - 161);
end
end;function WordToString(value: Word): string;
begin
Result := Chr(Hi(value)) + Chr(Lo(Value));
end;function isGB(value: string): Boolean;
Var
mHigh, mLow : integer;
begin
if (length(value)>=2) then
begin
mHigh := ord(value[1]);
mLow := ord(value[2]);
Result := False; if (mHigh in [$A1..$A9]) and (mLow in [$A1..$FE]) then Result := True; if (mHigh in [$B0..$F7]) and (mLow in [$A1..$FE]) then Result := True; if (mHigh in [$81..$A0]) and (mLow in [$40..$FE]) then Result := True; if (mHigh in [$AA..$FE]) and (mLow in [$40..$A0]) then Result := True; if (mHigh in [$A8..$A9]) and (mLow in [$40..$A0]) then Result := True;
end
else
Result := true;
end;function isGB(value: string): Boolean;
begin
if (length(value)>=2) then
begin
if (value[1] <= #161) and (value[1] >= #247) then
Result := false
else
if (value[2] <= #161) and (value[2] >= #254) then
Result := false
else
Result := true
end
else
Result := true;
end;function GBtoBIG5(value: string): string;
var
leng, idx : integer;
tmpStr : string[2];
Offset : integer;
output : string;
begin
output := '';
leng := length(value);
idx := 1;
while idx <= leng do
begin
tmpStr := value[idx]+ value[idx + 1];
if isGB(tmpStr) then
begin
offset:=GBOffset(tmpStr);
if (offset >= 0) and (offset <= 8177) then
begin
output := output + WordToString(GBOrder[offset]);
inc(idx);
end
else
output := output + value[idx] ;
end
else
output := output + value[idx] ; inc(idx, 1);
end;
Result := output;
end;function BIG5toGB(value: string): string;
var
leng, idx : integer;
tmpStr : string[2];
output : string;
offset : integer;
begin
output := '';
leng := length(value);
idx := 1;
while idx <= leng do
begin
tmpStr := value[idx]+ value[idx + 1];
if isBIG5(tmpStr) then
begin
offset:=BIG5Offset(tmpStr);
if (offset >= 0) and (offset <= 14757) then
begin
output := output + WordToString(BIG5Order[offset]);
inc(idx);
end
else
output := output + value[idx];
end
else
output := output + value[idx]; inc(idx);
end;
Result := output;
end;initialization BIG5Order[0] := $2020;
BIG5Order[1] := $A3AC;
BIG5Order[2] := $A1A2;
BIG5Order[3] := $A1A3;
BIG5Order[4] := $2020;
BIG5Order[5] := $A1A4;
BIG5Order[6] := $A3BB;
BIG5Order[7] := $A3BA;
BIG5Order[8] := $A3BF;
BIG5Order[9] := $A3A1;
BIG5Order[10] := $A1C3;
下载那个pas.然后把函数替换成上面的
方法也是网上找的
你试试成不成