如何实现只输入字母的可以索引到所有以该字母开头的汉字

zoujianqing 2008-12-11 10:13:51
如何实现只输入字母的可以索引到所有以该字母开头的汉字
例如:我输入J 那么就会出现:就,叫,加,家……
跟输入法一样的效果。
谢谢!
...全文
161 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyjdn 2009-04-02
  • 打赏
  • 举报
回复
我好像还有拼音转换表
eqapple 2008-12-16
  • 打赏
  • 举报
回复
5楼的只能处理一级二字
ahjoe 2008-12-15
  • 打赏
  • 举报
回复
汉字转拼音。
zoujianqing 2008-12-15
  • 打赏
  • 举报
回复
谢谢您们的回复!
icerainy 2008-12-15
  • 打赏
  • 举报
回复
看看你能不能看懂
Delphi中实现汉字拼音声母查询,unit代码如下:

unit Unit1;


interface


uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;


type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Edit1: TEdit;
Label1: TLabel;
procedure Edit1Change(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Edit1Enter(Sender: TObject);
procedure Edit1Exit(Sender: TObject);
private
{ Private declarations }
public
ResultList1:TStrings;
end;


var
Form1: TForm1;


procedure SearchByPyIndexStr(PYIndexStr :string);


implementation


{$R *.DFM}
function GetPyIndexChar(Hzchar:string):String;
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..$D1B8 : Result :='X';
$D1B9..$D4D0 : Result :='Y';
$D4D1..$D7F9 : Result :='Z';
else
Result := char(0);
end;
end;


procedure SearchByPyIndexStr(PYIndexStr :string);
label NotFound;
var
I, J :Integer;
Hzchar :String;
begin
For I:=0 to Form1.ListBox1.Items.Count-1 do
begin
For J:=1 to Length(PYIndexStr) do
begin
Hzchar :=Form1.ListBox1.Items[I][2*J-1]+Form1.ListBox1.Items[I][2*J];
if (PYIndexStr[J] <>'?') and (UpperCase(PYIndexStr[J])<>GetPyIndexChar(Hzchar)) then
goto NotFound;
end;
Form1.ResultList1.Add(Form1.ListBox1.Items[I]);
NotFound:
end;
end;


procedure TForm1.Edit1Change(Sender: TObject);
begin
if Edit1.Text<>'' then
begin
ListBox2.Items.Clear;
Form1.ResultList1.Clear;
SearchByPyIndexStr(edit1.text);
ListBox2.Items.AddStrings(ResultList1);
end;
end;


procedure TForm1.FormShow(Sender: TObject);
begin
ResultList1:=TStringList.Create;
end;


procedure TForm1.FormDestroy(Sender: TObject);
begin
ResultList1.Free;
end;


procedure TForm1.Edit1Enter(Sender: TObject);
begin
Edit1.Text:='';
end;


procedure TForm1.Edit1Exit(Sender: TObject);
begin
Edit1.Text:='请输入声母';
end;


end.
try__again 2008-12-11
  • 打赏
  • 举报
回复
有个汉字-->拼音的单元,
找来用一下,
比较用pos方法
yct0605 2008-12-11
  • 打赏
  • 举报
回复

//模糊查询 “like”
procedure Tmenumanage.Edit1Change(Sender: TObject);
var
zjm:string;
begin
zjm:=Edit1.Text;
adoq_dblist.SQL.Clear;
adoq_dblist.SQL.Add('select * from Menu where comments like ''%'+zjm+'%''');
adoq_dblist.Open;
end;
zoujianqing 2008-12-11
  • 打赏
  • 举报
回复

谢谢你们的意见!
谢谢!
bdmh 2008-12-11
  • 打赏
  • 举报
回复
用拼音控件吧,查找时,先把汉字转成拼音,然后Pos

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧