输入一个汉字字符串'我爱中国',怎么返回他的首拼'WAZG',我觉得好难哦。请高手点拨啊,说十声谢谢,请详细讲解一下首拼查询的算法谢谢 谢谢 谢谢 谢谢 谢谢 谢谢 谢谢 谢谢 谢谢 谢谢
解决方案 »
- TNodetable 类型转换成 TTreenode类型
- 求教XPMenu控件安装时存在的问题
- RmReport怎么设置保留几位小数
- delphi新手的异常问题,企盼有java,c++等其它语言经验的高手解答。
- 记录类型问题,高手请指教的?
- 请教为什么用TDcomconnection控件开发多层分布应用程序时在客户机中运行客户程序会提示“拒绝访问”???
- 如何实现像window任务管理器中CPU使用时间的动态图?(Tchart能实现吗?)请大虾帮忙帮忙
- 求助:关于Session的使用,最好给出代码!谢谢!
- Delphi cxDBTreeList 父节点选择同时也选择它的子节点
- 能在软盘上运行数据库吗?
- 请教非主窗口最小化问题??
- 用Delphi编写的OCX打包后为何不能正常使用
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
function GetPYIndexChar( hzchar:string):char;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }function TForm1.GetPYIndexChar(hzchar: string): char;
begin
case WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) of
$B0A1..$B0C4 : result := 'A';
$B0C5..$B2C0 : result := 'B';
$B2C1..$B4ED : result := 'C';
$B4EE..$B6E9 : result := 'D';
$B6EA..$B7A1 : result := 'E';
$B7A2..$B8C0 : result := 'F';
$B8C1..$B9FD : result := 'G';
$B9FE..$BBF6 : result := 'H';
$BBF7..$BFA5 : result := 'J';
$BFA6..$C0AB : result := 'K';
$C0AC..$C2E7 : result := 'L';
$C2E8..$C4C2 : result := 'M';
$C4C3..$C5B5 : result := 'N';
$C5B6..$C5BD : result := 'O';
$C5BE..$C6D9 : result := 'P';
$C6DA..$C8BA : result := 'Q';
$C8BB..$C8F5 : result := 'R';
$C8F6..$CBF9 : result := 'S';
$CBFA..$CDD9 : result := 'T';
$CDDA..$CEF3 : result := 'W';
$CEF4..$D188 : result := 'X';
$D1B9..$D4D0 : result := 'Y';
$D4D1..$D7F9 : result := 'Z';
else
result := char(0);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
s,t:String;
begin
s:='我爱中国';//有一个假设,那就是字符串s里面只有中文
t:='';
While s>'' do
begin
t:=t+GetPYIndexChar(Copy(s,1,2));
Delete(s,1,2);
end; Showmessage(t);
end;end.
var
Tint_StrLength:Integer;
Tint_I:Integer;
Tstr_Spell:String;
Tstr_Bg5:String;
begin
Tstr_Spell:='';
Tint_StrLength:=Length(Str);
if Tint_StrLength >0 then
begin
Tint_I:=1;
while Tint_I<=Tint_StrLength do
begin
case Integer(Str[Tint_I]) of
0..127:
begin
Tstr_Spell:=Tstr_Spell+(copy(Str,Tint_I,1));
Tint_I:=Tint_I+1;
end
else
begin
Tstr_Bg5:= copy(Str,Tint_I,2);
case WORD(Tstr_Bg5[1]) shl 8 + WORD(Tstr_Bg5[2]) of
$B0A1..$B0C4 : Tstr_Spell:=Tstr_Spell+ 'A';
$B0C5..$B2C0 : Tstr_Spell:=Tstr_Spell+ 'B';
$B2C1..$B4ED : Tstr_Spell:=Tstr_Spell+ 'C';
$B4EE..$B6E9 : Tstr_Spell:=Tstr_Spell+ 'D';
$B6EA..$B7A1 : Tstr_Spell:=Tstr_Spell+ 'E';
$B7A2..$B8C0 : Tstr_Spell:=Tstr_Spell+ 'F';
$B8C1..$B9FD : Tstr_Spell:=Tstr_Spell+ 'G';
$B9FE..$BBF6 : Tstr_Spell:=Tstr_Spell+ 'H';
$BBF7..$BFA5 : Tstr_Spell:=Tstr_Spell+ 'J';
$BFA6..$C0AB : Tstr_Spell:=Tstr_Spell+ 'K';
$C0AC..$C2E7 : Tstr_Spell:=Tstr_Spell+ 'L';
$C2E8..$C4C2 : Tstr_Spell:=Tstr_Spell+ 'M';
$C4C3..$C5B5 : Tstr_Spell:=Tstr_Spell+ 'N';
$C5B6..$C5BD : Tstr_Spell:=Tstr_Spell+ 'O';
$C5BE..$C6D9 : Tstr_Spell:=Tstr_Spell+ 'P';
$C6DA..$C8BA : Tstr_Spell:=Tstr_Spell+ 'Q';
$C8BB..$C8F5 : Tstr_Spell:=Tstr_Spell+ 'R';
$C8F6..$CBF9 : Tstr_Spell:=Tstr_Spell+ 'S';
$CBFA..$CDD9 : Tstr_Spell:=Tstr_Spell+ 'T';
$CDDA..$CEF3 : Tstr_Spell:=Tstr_Spell+ 'W';
$CEF4..$D1B8 : Tstr_Spell:=Tstr_Spell+ 'X';
$D1B9..$D4D0 : Tstr_Spell:=Tstr_Spell+ 'Y';
$D4D1..$D7F9 : Tstr_Spell:=Tstr_Spell+ 'Z';
else
Tstr_Spell:=Tstr_Spell+ char(0);
end;
Tint_I:=Tint_I+2;
end;
end;
end;
end;
Result:=Tstr_Spell;
end;
Edit Name Search
ListBox Name SourceList
Items 输入一些字符串,如姓名等,用于提供检索数据
ListBox Name ResultList
---- 3.键入以下两个函数 // 获取指定汉字的拼音索引字母,如:“汉”的索引字母是“H”
function GetPYIndexChar( hzchar:string):char;
begin
case WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) of
$B0A1..$B0C4 : result := 'A';
$B0C5..$B2C0 : result := 'B';
$B2C1..$B4ED : result := 'C';
$B4EE..$B6E9 : result := 'D';
$B6EA..$B7A1 : result := 'E';
$B7A2..$B8C0 : result := 'F';
$B8C1..$B9FD : result := 'G';
$B9FE..$BBF6 : result := 'H';
$BBF7..$BFA5 : result := 'J';
$BFA6..$C0AB : result := 'K';
$C0AC..$C2E7 : result := 'L';
$C2E8..$C4C2 : result := 'M';
$C4C3..$C5B5 : result := 'N';
$C5B6..$C5BD : result := 'O';
$C5BE..$C6D9 : result := 'P';
$C6DA..$C8BA : result := 'Q';
$C8BB..$C8F5 : result := 'R';
$C8F6..$CBF9 : result := 'S';
$CBFA..$CDD9 : result := 'T';
$CDDA..$CEF3 : result := 'W';
$CEF4..$D188 : result := 'X';
$D1B9..$D4D0 : result := 'Y';
$D4D1..$D7F9 : result := 'Z';
else
result := char(0);
end;
end;// 在指定的字符串列表SourceStrs中检索符合拼音索引字符串
PYIndexStr的所有字符串,并返回。
function SearchByPYIndexStr
( SourceStrs:TStrings;
PYIndexStr:string):string;
label NotFound;
var
i, j :integer;
hzchar :string;
begin
for i:=0 to SourceStrs.Count-1 do
begin
for j:=1 to Length(PYIndexStr) do
begin
hzchar:=SourceStrs[i][2*j-1]
+ SourceStrs[i][2*j];
if (PYIndexStr[j]<>'?') and
(UpperCase(PYIndexStr[j]) <>
GetPYIndexChar(hzchar)) then goto NotFound;
end;
if result='' then result := SourceStrs[i]
else result := result + Char
(13) + SourceStrs[i];
NotFound:
end;
end;4.增加编辑框Search的OnChange事件:
procedure TForm1.SearchChange(Sender: TObject);
var ResultStr:string;
begin
ResultStr:='';
ResultList.Items.Text := SearchByPYIndexStr
(Sourcelist.Items, Search.Text);
end;
---- 5.编译运行后,在编辑框Search中输入要查询字符串的拼音首字符序列,检索结果列表ResultList就会列出检索到的信息,检索中还支持“?”通配符,对于难以确定的的文字使用“?”替代位置,可以实现更复杂的检索。
\\ - - //
( @ @ )
+---------------------oOOoo-(?)ooOOo---------------------+
| |
| 欢迎访问 http://www.coderpub.com 技术论坛 |
| delphi,asp.net,C#,j2me,软件工程,企业管理 |
| http://www.coderpub.com |
| |
| Ooooo |
+-----------------------ooooO--( )---------------------+
( ) )|/
\|( (_/
\_)
library Prgetwbpy;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
//拼音,五笔 1: 拼音 2:五笔 3: 拼音简码 4:五笔简码
uses
ShareMem, SysUtils,Windows,
Classes;{$R *.res}
{$R wbtext.res}
function GetWbPy(hzstr: string; pytype: integer):String;stdcall;
var
I: Integer;
allstr: string;
hh: THandle;
pp: pointer;
ss: TStringList;
function retturn_wbpy(tempstr: string; tqtype: integer): String;
var
outstr, str: string;
i: integer;
begin
//################### 汉字查询电位
i := 0;
while i <= ss.Count - 1 do
begin
str := ss.Strings[i];
if (tempstr = trim(str[1] + str[2])) or (tempstr = trim(str[3] + str[4])) then
begin
str := ss.Strings[i];
Break;
end;
i := i + 1;
end;
//################### outstr := ''; //提取编码
if tqtype = 1 then
begin
for i := pos('①', str) + 2 to pos('②', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
if tqtype = 2 then
begin
for i := pos('②', str) + 2 to pos('③', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end; if tqtype = 3 then
begin
for i := pos('③', str) + 2 to pos('④', str) - 1 do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end; if tqtype = 4 then
begin
for i := pos('④', str) + 2 to length(str) do
if str[i] <> '' then if outstr = '' then outstr := str[i] else outstr := outstr + str[i];
end;
Result := trim(outstr);
end;
begin
//加载资源文件,将内容赋值给 s
ss := TStringList.Create;
hh := FindResource(hInstance, 'mywb', 'TXT');
hh := LoadResource(hInstance, hh);
pp := LockResource(hh);
ss.Text := pchar(pp);
UnLockResource(hh);
FreeResource(hh);
allstr := '';
i := 0;
while i <= length(hzstr) do //提取汉字字符
begin
if (Ord(hzstr[I]) > 127) then
begin
if allstr = '' then allstr := retturn_wbpy(hzstr[I] + hzstr[I + 1], pytype) else allstr := allstr + retturn_wbpy(hzstr[I] + hzstr[I + 1], pytype);
i := i + 2;
end
else
begin
if allstr = '' then allstr := hzstr[I] else allstr := allstr + hzstr[I];
i := i + 1;
end;
end;
ss.Free;
Result := trim(allstr);
end;
exports
GetWbPy;
begin
end.
//调用方式
//拼音,五笔 1: 拼音 2:五笔 3: 拼音简码 4:五笔简码
//edit1.text=getwbpy(edit2.text,3)
我在DELPHI6测试没问题,绝对可以