急急急 关于vb拼音查找问题
发布网友
发布时间:2024-07-03 20:07
我来回答
共1个回答
热心网友
时间:2024-07-13 16:20
呵呵,累死了,但还有一些字不能辨认,对照集到我的博客找
Default.aspx.vb-----------------------------------------------
Partial Class Code_拼音模糊查找_Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'这里可将数据库某字段列读取到ArrayList
Dim word As New ArrayList
word.Add("天安门")
word.Add("安琪儿")
word.Add("大前门")
word.Add("大灰狼")
Session("word") = word
End Sub
Protected Sub se_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles se.Click
Dim jianpin As String = strPing(words.Text) '获得简拼
jp.Text = jianpin
Dim word As ArrayList = Session("word")
Dim jieguo As String = ""
ListBox1.Items.Clear()
For i As Integer = 0 To word.Count - 1 Step 1
If strPing(word.Item(i)).ToString.ToUpper.IndexOfAny(jianpin.ToUpper) >= 0 Then
ListBox1.Items.Add(word.Item(i).ToString)
End If
Next
End Sub
Public Function strPing(ByVal str As String) As String
Dim reStr As String = ""
For i As Integer = 0 To Len(str) - 1
reStr = reStr & wordPing(Mid(str, i + 1, 1))
Next
Return reStr
End Function
Public Function wordPing(ByVal word As String) As String
'这个对比表只是一个大概,还不完善,对不少汉字不能识别
Dim myPing As Long = 65536 + Asc(word)
Select Case myPing
Case 45217 To 45252
Return "A"
Case 45253 To 45760
Return "B"
Case 45761 To 46317
Return "C"
Case 46318 To 46825
Return "D"
Case 46826 To 47009
Return "E"
Case 47010 To 47296
Return "F"
Case 47297 To 47613
Return "G"
Case 47614 To 48118
Return "H"
Case 48119 To 49061
Return "J"
Case 49062 To 49323
Return "K"
Case 49324 To 49895
Return "L"
Case 49896 To 50370
Return "M"
Case 50371 To 50613
Return "N"
Case 50906 To 51386
Return "O"
Case 50622 To 50905
Return "P"
Case 45217 To 45252
Return "Q"
Case 51387 To 51445
Return "R"
Case 51446 To 52217
Return "S"
Case 52218 To 52697
Return "T"
Case 52698 To 52979
Return "W"
Case 52980 To 53640
Return "X"
Case 53689 To 54480
Return "Y"
Case 54481 To 65536
Return "Z"
Case Else
'返回原字符
Return word
End Select
End Function
End Class
Default.aspx--------------------------------------------------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Code_拼音模糊查找_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>拼音模糊查找</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="words" runat="server"></asp:TextBox>
<asp:Button ID="se" runat="server" Text="搜索" Width="83px" />
<br />
<br />
简拼<asp:TextBox ID="jp" runat="server" Width="93px"></asp:TextBox>
<br />
<br />
相关词组<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="123px" Width="126px"></asp:ListBox>
</div>
</form>
</body>
</html>