Asp. NET to implement the method of fuzzy query by Pinyin Code _ practical skills

Source: Internet
Author: User

The whole process is divided into two parts: the generation of phonetic code fields, the fuzzy query by phonetic code.

Implementation of batch generation of phonetic code fields:

 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, we can see their hobbies and set!

  } string updatesql = "Update TEST001 Set Pym = ' + Pym +" ' where mc= ' "+ MC +" ";
 Dac.update (Updatesql); } Dr. 
 Close (); Response.Write ("Successful operation! ');" <script>alert
 </script> ");  Getchinesespell method for Strtopinyin class (kanji Pinyin): 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 not kanji, direct output 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 in the encoding range, check the Chinese character list for conversion output foreach (String strlist in Strchinesecharlist)
   {if (Strlist.indexof (Vchar) > 0) {mystr.append (strlist[0]);
 }}} return Mystr.tostring (); }

Fuzzy query by phonetic code:

This simple, with select query, where conditions with like can, I believe we will be able to operate.

believe that in the realization of the user input Pinyin code for the data of the fuzzy query function, we can use today to learn the implementation by Pinyin code fuzzy query.

Related Article

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: 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.