VB.NET 获得拼音码
代码
''' <summary>
''' 获得拼音码
''' Add by pwm 2010.07.17
''' </summary>
''' <param name="str">字符串</param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function getPYChar(ByVal str As String) As String
Dim pinyin As Char
Dim c As Char
Dim array() As Byte
Dim i As Integer
Dim sb As New System.Text.StringBuilder(str.Length)
For Each c In str.ToCharArray
pinyin = c
array = System.Text.Encoding.Default.GetBytes(New Char() {c})
If array.Length = 2 Then
i = array(0) * &H100 + array(1)
If i < &HB0A1 Then
pinyin = c
ElseIf i < &HB0C5 Then
pinyin = "A"
ElseIf i < &HB2C1 Then
pinyin = "B"
ElseIf i < &HB4EE Then
pinyin = "C"
ElseIf i < &HB6EA Then
pinyin = "D"
ElseIf i < &HB7A2 Then
pinyin = "E"
ElseIf i < &HB8C1 Then
pinyin = "F"
ElseIf i < &HB9FE Then
pinyin = "G"
ElseIf i < &HBBF7 Then
pinyin = "H"
ElseIf i < &HBFA6 Then
pinyin = "J"
ElseIf i < &HC0AC Then
pinyin = "K"
ElseIf i < &HC2E8 Then
pinyin = "L"
ElseIf i < &HC4C3 Then
pinyin = "M"
ElseIf i < &HC5B6 Then
pinyin = "N"
ElseIf i < &HC5BE Then
pinyin = "O"
ElseIf i < &HC6DA Then
pinyin = "P"
ElseIf i < &HC8BB Then
pinyin = "Q"
ElseIf i < &HC8F6 Then
pinyin = "R"
ElseIf i < &HCBFA Then
pinyin = "S"
ElseIf i < &HCDDA Then
pinyin = "T"
ElseIf i < &HCEF4 Then
pinyin = "W"
ElseIf i < &HD1B9 Then
pinyin = "X"
ElseIf i < &HD4D1 Then
pinyin = "Y"
ElseIf i < &HD7FA Then
pinyin = "Z"
End If
End If
sb.Append(pinyin)
Next
Return sb.ToString()
End Function