Delphi uses the first character sequence of pinyin for retrieval

Source: Internet
Author: User

In daily work and life, we often use an electronic notepad to find personal address book information, or query customer files or business materials in the application of the organization. In this process, we often need to enter a large amount of Chinese characters, it is already a headache for people who are familiar with computers. users who are not familiar with computers or do not understand Chinese character INPUT are simply daunting. As a new attempt of data retrieval technology, the author explores using the first character sequence of Chinese characters and Pinyin as a search keyword, so that users do not need to use Chinese characters, you only need to simply enter the first character of each Chinese character to be queried. For example, if you want to search for the keyword "People's Bank of China", you only need to enter "zgrmyh ". The author hopes that the following example will serve as a reference for the majority of computer peers, making our programs more convenient and easy to use.
The principle is very simple. Find out the inner code range of Chinese characters whose first character is "A" to "Z" in the Chinese character table. In this way, for a Chinese character to be retrieved, you only need to check the range of its inner code to determine its first character.

The program is simpler, including three controls: A list stores all the information to be searched; A list stores the information to be searched; an edit box is used to enter the search keywords (that is, the first character sequence of Pinyin ). The details are as follows:

1. Go to Delphi to create a new project: project1

2. Create the following controls on form1 and fill in the attributes:

Control Type property name property value
Edit name search
ListBox name sourcelist
Items input strings, such as names, to provide data retrieval
ListBox name resultlist

3. type the following two functions:

// Obtain the pinyin index letters of a specified Chinese character. For example, the index Letter "Han" is "H"
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;

// Retrieve the pinyin index string from the specified string list sourcestrs
All strings of pyindexstr, and return.
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. added the onchange event in the search edit box:

Procedure tform1.searchchange (Sender: tobject );
VaR resultstr: string;
Begin
Resultstr: = '';
Resultlist. Items. Text: = searchbypyindexstr
(Sourcelist. Items, search. Text );
End;

5. After compilation and running

In the search box that appears, enter the first character sequence of the string to be queried. The resultlist in the search result list lists the retrieved information. The "?" Wildcard character, use "?" For difficult to determine the text The replacement location can achieve more complex retrieval.

 

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.