In WPF, Chinese characters are searched by pinyin, and Chinese characters are searched by wpf pinyin.

Source: Internet
Author: User

In WPF, Chinese characters are searched by pinyin, and Chinese characters are searched by wpf pinyin.

1. For a touch screen project in WPF, you need to enter a name, but the screen does not support Chinese character input. The use of the virtual keyboard is unstable. In order to solve this problem, we hereby handle it.

2. Create a new class conversion class, which initializes an array containing Pinyin and frequently used Chinese characters in pinyin.

3. Compare the corresponding Chinese characters according to the pinyin alphabet, and then split the Chinese characters to obtain a single Chinese character.

Example:

Private static readonly string [] [] _ Allhz =
New string [] []
{
New string [] {"A", "ah "},
New string [] {"Ai", "Ai is suffering from cancer "},
New string [] {"An", ""},
New string [] {"Ang", "Ang Yu Yang Yu yu "},
New string [] {"Ao", "Ao "},
New string [] {"Ba", "unplug Ba Ma "},
New string [] {"Bai", "Bai "},

~~~~~~~~ // Save a few
New string [] {"Zui", "the most drunk heap Tsui "},
New string [] {"Zun ", "zookeeper has been offering a good selection of zookeeper, Zookeeper, Zookeeper, and zookeeper "},
New string [] {"Zuo", "sitting on the left seat, cutting and cutting "}
};

 

/// <Summary>
/// Convert pinyin into Chinese Characters
/// </Summary>
/// <Param name = "str"> </param>
/// <Returns> </returns>
Public static string ConvertPzToHz (string str)
{
Str = str. ToLower ();

If (str = null)
Return null;
Byte [] bAry = new byte [2];
StringBuilder rtnSb = new StringBuilder ();
For (int j = 0; j <_ Allhz. Length; j ++)
{
String py = _ Allhz [j] [0]. ToLower ();

If (py. IndexOf (str )! =-1)
{
RtnSb. Append (_ Allhz [j] [1]);
Break;
}
}
Return rtnSb. ToString ();
}

 

// Break down Chinese character strings

Char [] chars = strMsg. ToCharArray ();

 


Search data based on Chinese characters and Pinyin

ASP Method

<Script language = "vbs" src = "spellcode. vbs"> </script>
'Get the pinyin abbreviation of the customer abbreviation
<%
Function getpy ()
Dim str
Dim I
Strw.document.all.txt ContactName. value
Dim ret
For I = 1 to len (str)
Ret = ret & getpychar (mid (str, I, 1 ))
Next
Document.all.txt SpellCode. value = ret
End function
Getpychar = char
End if
End function
SpellCode. vbs
'Get the first letter of Chinese pinyin
Function getpychar (char)
Dim tmp
Tmp = 65536 + asc (char)
If (tmp> = 45217 and tmp <= 45252) then
Getpychar = ""
Elseif (tmp & gt; = 45253 and tmp <= 45760) then
Getpychar = "B"
Elseif (tmp & gt; = 45761 and tmp <= 46317) then
Getpychar = "C"
Elseif (tmp & gt; = 46318 and tmp <= 46825) then
Getpychar = "D"
Elseif (tmp & gt; = 46826 and tmp <= 47009) then
Getpychar = "E"
Elseif (tmp & gt; = 47010 and tmp <= 47296) then
Getpychar = "F"
Elseif (tmp & gt; = 47297 and tmp <= 47613) then
Getpychar = "G"
Elseif (tmp & gt; = 47614 and tmp <= 48118) then
Getpychar = "H"
Elseif (tmp & gt; = 48119 and tmp <= 49061) then
Getpychar = "J"
Elseif (tmp & gt; = 49062 and tmp <= 49323) then
Getpychar = "K"
Elseif (tmp & gt; = 49324 and tmp <= 49895) then
Getpychar = "L"
Elseif (tmp & gt; = 49896 and tmp <= 50370) then
Getpychar = "M"
Elseif (tmp & gt; = 50371 and tmp <= 50613) then
Getpychar = "N"
Elseif (tmp & gt; = 50614 and tmp <= 50621) then
Getpychar = "O"
Elseif (tmp> = 50622 and tmp <...... the remaining full text>

How to implement Chinese pinyin search in Baidu search? input pinyin can search records with this Chinese Character in the database

A tool called pinyin4j is used to convert Chinese characters into corresponding pinyin characters. You only need to convert the keywords in the database into Chinese pinyin, and then match these words when entering Chinese pinyin, you can.

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