ASP. NET Implementation of Fuzzy Query by Pinyin Code

  • 2021-07-01 07:19:06
  • OfStack

The whole process is divided into two parts: generating Pinyin code field and fuzzy query according to Pinyin code.

Realization of batch generation of pinyin 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 here 6 Bit, everyone can see their own hobbies! 
  } 
  string updateSql = "update TEST001 set pym ='" + pym + "' where mc='" + mc + "'";

  dac.update(updateSql);
 }
 dr.Close(); 
 Response.Write("<script>alert(' Operation successful !');</script>");
 }

StrToPinyin  Class GetChineseSpell Methods (take Chinese phonetic 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, it will be output directly  
  if ((int)vChar < 19968 || (int)vChar > 40869)
  {
  myStr.Append(char.ToUpper(vChar));
  }
  else if ((int)vChar >= 19968 && (int)vChar <= 40869)
  {
  //  If character Unicode If the code is in the coding range,   Look up the list of Chinese characters for conversion and output  
  foreach (string strList in strChineseCharList)
  {
   if (strList.IndexOf(vChar) > 0)
   {
   myStr.Append(strList[0]);
   break;
   }
  }
  }
 }
 return myStr.ToString();
 }

Fuzzy query by Pinyin code:

This simple, with select query, where conditions with LIKE, I believe everyone 1 will operate.

I believe that in the future, when realizing the fuzzy query function of data according to the Pinyin code input by users, we can use ASP. NET learned today to realize fuzzy query according to Pinyin code.


Related articles: