应该是大富翁上最全的汉字转拼音的函数。送给大家发分拜年!(300分)

  • 主题发起人 主题发起人 火龙真人
  • 开始时间 开始时间

火龙真人

Unregistered / Unconfirmed
GUEST, unregistred user!
这篇应该是能检测汉字最多的函数。朋友给我的C语言的函数我转成DELPHI的了
他做成了DLL function ctoe(str:string):string;external 'kk.dll';
我是用来对于他和我转后效果是不是一样的。具体用函数的时候请把他去掉
function strtopy(thestr:widestring):string;
字符串的检测
function pyindex(hzchar:string):string;
一个字的检测
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
function ctoe(str:string):string;external 'kk.dll';
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Edit3: TEdit;
function strtopy(thestr:widestring):string;
function pyindex(hzchar:string):string;
procedure Button1Click(Sender: TObject);
procedure Edit2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
function tform1.strtopy(thestr:widestring):string;
var strcount:integer;
begin

for strcount:=1 to length(thestr)do
result:=result+pyindex(thestr[strcount]);
end;

function tform1.pyindex(hzchar:string):string;
var
pytable:string;
H,L,W:INTEGER;
begin
result:='?';
pytable:='';
if length(hzchar)=1 then
begin
result:=hzchar;
exit;
end;

pytable:='CJWGNSPGCGNE[Y[BTYYZDXYKYGT[JNNJQMBSGZSCYJSYY[PGKBZGY[YWJKGKLJYWKPJQHY[W[DZLSGMRYPYWWCCKZNKYYGTTNJJNYKKZYTCJNMCYLQLYPYQFQRPZSLWBTGKJFYXJWZLTBNCXJJJJTXDTTSQZYCDXXHGCK[PHFFSS[YBGXLPPBYLL[HLXS[ZM[JHSOJNGHDZQYKLGJHSGQZHXQGKEZZWYSCSCJXYEYXADZPMDSSMZJ'+
'ZQJYZC[J[WQJBYZPXGZNZCPWHKXHQKMWFBPBYDTJZZKQHYLYGXFPTYJYYZPSZLFCHMQSHGMXXSXJ[[DCSBBQ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YZLYCBLYDPDQYSXQZBYTDKYXJY[CNRJMPDJGKLCLJBCTBJDDBBLBLCZQRPPXJCJLZCSHLTOLJNMDDDLNGKAQHQHJGYKHE'+
'ZNMSHRP[QQJCHGMFPRXHJGDYCHGHLYRZQLCYQJNZSQTKQJYMSZSWLCFQQQXYFGGYPTQWLMCRNFKKFSYYLQBMQAMMMYXCTPSHCPTXXZZSMPHPSHMCLMLDQFYQXSZYYDYJZZHQPDSZGLSTJBCKBXYQZJSGPSXQZQZRQTBDKYXZKHHGFLBCSMDLDGDZDBLZYYCXNNCSYBZBFGLZZXSWMSCCMQNJQSBDQSJTXXMBLTXZCLZSHZCXRQJGJ'+
'YLXZFJPHYMZQQYDFQJJLZZNZJCDGZYGCTXMZYSCTLKPHTXHTLBJXJLXSCDQXCBBTJFQZFSLTJBTKQBXXJJLJCHCZDBZJDCZJDCPRNPQCJPFCZLCLZXZDMXMPHJSGZGSZZQLYLWTJPFSYASMCJBTZKYCWMYTCSJJLJCQLWZMALBXYFBPNLSFHTGJWEJJXXGLLJSTGSHJQLZFKCGNNNSZFDEQFHBSAQTGYLBXMMYGSZLDYDQMJJRGBJ'+
'TKGDHGKBLQKBDMBYLXWCXYTTYBKMRTJZXQJBHLMHMJJZMQASLDCYXYQDLQCAFYWYXQHZ';

H:=word(HZChar[1]);
L:=word(HZchar[2]);
W:=(H-160)*100+L-160;
IF (w>1600) and (w<5590) then
begin

case w of
1601..1636:RESULT:='A';
1637..1832:RESULT:='B';
1833..2077:RESULT:='C';
2078..2273:RESULT:='D';
2274..2301:RESULT:='E';
2302..2432:RESULT:='F';
2433..2593:RESULT:='G';
2594..2786:RESULT:='H';
2787..3105:RESULT:='J';
3106..3211:RESULT:='K';
3212..3471:RESULT:='L';
3472..3634:RESULT:='M';
3635..3721:RESULT:='N';
3722..3729:RESULT:='O';
3730..3857:RESULT:='P';
3858..4026:RESULT:='Q';
4027..4085:RESULT:='R';
4086..4389:RESULT:='S';
4390..4557:RESULT:='T';
4558..4683:RESULT:='W';
4684..4924:RESULT:='X';
4925..5248:RESULT:='Y';
5249..5589:RESULT:='Z';
end;
end
else
begin
W:=(H-160-56)*94+L-160;
IF (W>=1) AND (W<=3008) then
RESULT:=PYTABLE[W];
// SHOWMESSAGE(INTTOSTR(W));
end;


end;

procedure TForm1.Button1Click(Sender: TObject);
begin
EDIT1.Text:=strtopy(EDIT2.Text);
edit3.Text:=ctoe(ediT2.Text);
end;

procedure TForm1.Edit2Change(Sender: TObject);
begin
EDIT1.Text:=strtopy(EDIT2.Text);
end;

end.


以下是原来的C代码
//==================转化成的是大写字母====================================
//-----------------直接把中文转换成拼音的自动获取,只能获取每个字第一个字母------------------------
AnsiString Tdm1::ConvertHZToPY(char *as_HzString)
{
static int li_SecPosValue[]={1601,1637,1833,2078,2274,2302,2433,2594,2787,3106,3212,3472,3635,3722,3730,3858,4027,4086,4390,4558,4684,4925,5249};
static char* lc_FirstLetter[] = {"A", "B","C","D","E","F","G","H","J","K","L","M","N","O","P","Q","R","S","T","W","X","Y","Z"};
static char* ls_SecondSecTable =
"CJWGNSPGCGNE[Y[BTYYZDXYKYGT[JNNJQMBSGZSCYJSYY[PGKBZGY[YWJKGKLJYWKPJQHY[W[DZLSGMRYPYWWCCKZNKYYGTTNJJNYKKZYTCJNMCYLQLYPYQFQRPZSLWBTGKJFYXJWZLTBNCXJJJJTXDTTSQZYCDXXHGCK[PHFFSS[YBGXLPPBYLL[HLXS[ZM[JHSOJNGHDZQYKLGJHSGQZHXQGKEZZWYSCSCJXYEYXADZPMDSSMZJZQJYZC[J[WQJBYZPXGZNZCPWHKXHQKMWFBPBYDTJZZKQHY"
"LYGXFPTYJYYZPSZLFCHMQSHGMXXSXJ[[DCSBBQBEFSJYHXWGZKPYLQBGLDLCCTNMAYDDKSSNGYCSGXLYZAYBNPTSDKDYLHGYMYLCXPY[JNDQJWXQXFYYFJLEJPZRXCCQWQQSBNKYMGPLBMJRQCFLNYMYQMSQYRBCJTHZTQFRXQHXMJJCJLX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GGYPTQWLMCRNFKKFSYYLQBMQAMMMYXCTPSHCPTXXZZSMPHPSHMCLMLDQFYQXSZYYDYJZZHQPDSZGLSTJBCKBXYQZJSGPSXQZQZRQTBDKYXZK"
"HHGFLBCSMDLDGDZDBLZYYCXNNCSYBZBFGLZZXSWMSCCMQNJQSBDQSJTXXMBLTXZCLZSHZCXRQJGJYLXZFJPHYMZQQYDFQJJLZZNZJCDGZYGCTXMZYSCTLKPHTXHTLBJXJLXSCDQXCBBTJFQZFSLTJBTKQBXXJJLJCHCZDBZJDCZJDCPRNPQCJPFCZLCLZXZDMXMPHJSGZGSZZQLYLWTJPFSYASMCJBTZKYCWMYTCSJJLJCQLWZMALBXYFBPNLSFHTGJWEJJXXGLLJSTGSHJQLZFKCGNNNSZFDEQ"
"FHBSAQTGYLBXMMYGSZLDYDQMJJRGBJTKGDHGKBLQKBDMBYLXWCXYTTYBKMRTJZXQJBHLMHMJJZMQASLDCYXYQDLQCAFYWYXQHZ";

AnsiString result = "";
int H,L,W;
unsigned int i, stringlen = strlen(as_HzString);
int j;
for( i = 0;
i < stringlen;
i ++ )
{
H = (unsigned char)(as_HzString[i + 0]);
L = (unsigned char)(as_HzString[i + 1]);
if(H < 0xA1 || L < 0xA1)
{
result += as_HzString;
continue;
}
else
W = (H - 160) * 100 + L - 160;
if(W > 1600 &amp;&amp;
W < 5590)
{
for(j = 22;
j >= 0;
j --)
if(W >= li_SecPosValue[j])
{
result += lc_FirstLetter[j];
i ++;
break;
}
continue;
}
else
{
i ++;
W = ( H - 160 - 56 )*94 + L - 161;
if(W >= 0 &amp;&amp;
W <= 3007)
result += ls_SecondSecTable[W];
else
{
result += (char)H;
result += (char)L;
}
}
}
return result;
}
 
多音字怎么办,老兄。
其实还有一种办法,ms已经有api函数了。
 
好象繁體的不行耶,哈
up
 
谢谢,我也要一用!!!
 
>>ms已经有api函数了
什么api?
楼主 谢了。
是好东东
 
恩!确实还有些字没有,不过把PYTABLE干脆放到文件里算了
我再写个程序为这个文件加对应字,你们应该看出,这个函数
主要部分就是 PYTABLE,其实就是一一对应,很笨的方法,
 
对GBK好用?
最好是对拼音输入法下手[:D]
 
最笨的也就是最有效的方法,如果你有更好的方法,可以提出来
我的这个认的汉字可是很全的,可以看一下例子程序
http://www.playicq.com/dispdoc.php?t=&amp;id=2259
 
先谢谢楼主,
不过方法有很多,大家共同研究吧!
 
谢谢你了。是的好好研究研究。
 
是好东东,给楼主拜年!
 
试了一下不错
比我原来收藏的一个识字多了
原来的一个在
Delphi园地
http://mydelphi.8u8.com上的一个链接函数库
 
太好了,谢谢!
 
后退
顶部