ASP. NET implements fuzzy query by pinyin code, and asp.net fuzzy query

Source: Internet
Author: User

ASP. NET implements fuzzy query by pinyin code, and asp.net fuzzy query

The entire process is divided into two parts: generate the pinyin code segment and perform fuzzy query by the pinyin code segment.

Batch generation of Pinyin code segments:

Protected void Button1_Click1 (object sender, EventArgs e) {string strSQL; strSQL = "select mc from TEST001"; IDataReader dr = dac. dataReaderQuery (strSQL); while (dr. read () {string mc = dr ["mc"]. toString (); string pym = StrToPinyin. getChineseSpell (mc); if (pym. length> 6) {pym = pym. substring (0, 6); // I only went to 6 places here. You can check your hobbies!} String updateSql = "update TEST001 set pym = '" + pym + "'where mc ='" + mc + "'"; dac. update (updateSql);} dr. close (); Response. write ("<script> alert ('Operation successful! '); </Script> ");} The GetChineseSpell method of the StrToPinyin class (using Chinese characters and Pinyin letters): public static string GetChineseSpell (string strText) {if (strText = null | strText. length = 0) return strText; System. text. stringBuilder myStr = new System. text. stringBuilder (); foreach (char vChar in strText) {// if it is not a Chinese character, if (int) vChar <19968 | (int) vChar> 40869) {myStr. append (char. toUpper (vChar);} else if (int) vChar >=19968 & (int) vChar <= 40869) {// if the character Unicode encoding is within the encoding range, query the Chinese Character List and convert the output foreach (string strList in strChineseCharList) {if (strList. indexOf (vChar)> 0) {myStr. append (strList [0]); break ;}}} return myStr. toString ();}

Fuzzy search by pinyin code:

This is simple. You can use select to query and the where condition to use LIKE. I believe everyone will perform the operation.

I believe that in the future, we will be able to use ASP. NET, which we have learned today, to perform fuzzy queries based on pinyin codes when we implement the fuzzy query function of data by user input pinyin codes.

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.