扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:中国IT实验室 来源:中国IT实验室 2007年10月2日
关键字:
在本页阅读全文(共2页)
For Each s As Char In line.ToCharArray
If IsTrue(s) Then
mBuilder.Append(GetPinyin(s, isgetfirst))
Else
mBuilder.Append(s)
End If
Next
Return mBuilder.ToString
End Function
Private Function GetPinyin(ByVal word As String, ByVal isgetfirst As Boolean) As String
Dim mResult As String = word
Dim mArray As String() = PinYinArray(ChineseCode(word)) '取拼音组
If Not mArray Is Nothing Then
If mArray.Length = 1 Or isgetfirst Then
mResult = mArray(0) '单音的
Else
mResult = String.Format("({0})", String.Join(",", mArray)) '多音的用括号括住,拼音间用逗号隔开
End If
End If
Return mResult
End Function
'取拼音组
Private Function PinYinArray(ByVal code As String) As String()
Dim mRow As dsPinYin.PinYinRow = Me.gDataSet.PinYin.FindBy代码(code)
If mRow Is Nothing Then Return Nothing
Return mRow.拼音.Split(" "c)
End Function
''' <summary>
''' 按拼音查字
''' </summary>
''' <param name="pinyin">拼音</param>
Public Function WordArray(ByVal pinyin As String) As String()
Dim mRows As dsPinYin.PinYinRow() = CType(Me.gDataSet.PinYin.Select(String.Format("拼音 LIKE '%{0}%'", pinyin)), dsPinYin.PinYinRow())
Dim mResult(-1) As String
For i As Integer = 0 To mRows.Length - 1
If Array.IndexOf(mRows(i).拼音.Split(" "c), pinyin) <> -1 Then
Me.Append(mResult, mRows(i).汉字)
End If
Next
Return mResult
End Function
''' <summary>
''' 按拼音查字
''' </summary>
''' <param name="pinyin">拼音</param>
Public Function Words(ByVal pinyin As String) As String
Return String.Concat(WordArray(pinyin))
End Function
''' <summary>
''' 汉字代码
''' </summary>
''' <param name="word">单个汉字</param>
Public Shared Function ChineseCode(ByVal word As String) As String
If Not IsTrue(word) Then Return Nothing
Dim bytes() As Byte = System.Text.Encoding.Default.GetBytes(word)
Return String.Concat(Hex(bytes(0)), Hex(bytes(1)))
End Function
''' <summary>
''' 是否是单个汉字
''' </summary>
''' <param name="word">字符</param>
Public Shared Function IsTrue(ByVal word As String) As Boolean
If word Is Nothing Then Return False
Return System.Text.RegularExpressions.Regex.IsMatch(word, "^[\u4e00-\u9fa5]$")
End Function
Private Sub Append(ByRef collection As String(), ByVal value As String)
ReDim Preserve collection(collection.Length)
collection(collection.Length - 1) = value
End Sub
End Class
End Namespace
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者