Search using the alphabetic alphabet

Source: Internet
Author: User
In fact, the idea of solving this problem is very simple. That is to find out the inner code range of Chinese characters whose initials are "a" to "Z" in the Chinese character table, you only need to check the inner code within the range of which is the first letter to determine its first letter.
Next, complete a demo program and select the "file | New Application" menu command, add one label component, one bevel component, one edit component, and two ListBox components to the default form. After setting the attributes and layout of each component, add the following code to the onchange event of the edit component. Program codeProcedure tform1.edit1change (Sender: tobject );
VaR resultstr: string;
Begin
Resultstr: = '';
Listbox2.items. Text: = searchbypyindexstr (listbox1.items, edit1.text );
End;

The code of the searchbypyindexstr function used here is as follows. Its function is to retrieve all strings that match the pinyin index string in the string list. You can add it to the implementation section of the form unit file.Program codeFunction 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;

The getpyindexchar function referenced in the above program is used to obtain the pinyin index letters of a specified Chinese character. For example, the index Letter of "du" is "D ". The code of this function is as follows, and it is also added to the implementation section of the form unit file.Program code

Function getpyindexchar (hzchar: string): Char ;
Begin
Case word (hzchar [1]) SHL 8 + word (hzchar [2
])
$ 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;

After that, press the F9 key to run the program. After you enter the first letter of the person's name in the edit box, the corresponding name is automatically retrieved in listbox2.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.