当前位置:编程学习 > VB >>

如何用vb获得输入汉字的拼音码?

如题 参考 这个是vb2008的你改改

Public Function hz2py(ByVal hz As String) As String 
        Dim sarr As Byte() = System.Text.Encoding.Default.GetBytes(hz) 
        Dim len As Integer = sarr.Length 
        If len > 1 Then 
            Dim array(2) As Byte 
            array = System.Text.Encoding.Default.GetBytes(hz) 
            Dim i1 As Integer = CShort(array(0) - Asc(ControlChars.NullChar)) 
            Dim i2 As Integer = CShort(array(1) - Asc(ControlChars.NullChar)) 

            Dim tmp As Integer = i1 * 256 + i2 
            Dim getpychar As String = "*" 
            If tmp >= 45217 And tmp <= 45252 Then 
                getpychar = "A" 
            End If 
            If tmp >= 45253 And tmp <= 45760 Then 
                getpychar = "B" 
            End If 
            'If tmp >= 47761 And tmp <= 46317 Then 
            If tmp >= 45765 And tmp <= 46294 Then 
                getpychar = "C" 
            End If 
            If tmp >= 46318 And tmp <= 46825 Then 
                getpychar = "D" 
            End If 
            If tmp >= 46826 And tmp <= 47009 Then 
                getpychar = "E" 
            End If 
            If tmp >= 47010 And tmp <= 47296 Then 
                getpychar = "F" 
            End If 
            If tmp >= 47297 And tmp <= 47613 Then 
                getpychar = "G" 
            End If 
            If tmp >= 47614 And tmp <= 48118 Then 
                getpychar = "H" 
            End If 
            If tmp >= 48119 And tmp <= 49061 Then 
                getpychar = "J" 
            End If 
            If tmp >= 49062 And tmp <= 49323 Then 
                getpychar = "K" 
            End If 
            If tmp >= 49324 And tmp <= 49895 Then 
                getpychar = "L" 
            End If 
            If tmp >= 49896 And tmp <= 50370 Then 
                getpychar = "M" 
            End If 
            If tmp >= 50371 And tmp <= 50613 Then 
                getpychar = "N" 
            End If 
            If tmp >= 50614 And tmp <= 50621 Then 
                getpychar = "O" 
            End If 
            If tmp >= 50622 And tmp <= 50905 Then 
                getpychar = "P" 
            End If 
            If tmp >= 50906 And tmp <= 51386 Then 
                getpychar = "Q" 
            End If 
            If tmp >= 51387 And tmp <= 51445 Then 
                getpychar = "R" 
            End If 
            If tmp >= 51446 And tmp <= 52217 Then 
                getpychar = "S" 
            End If 
            If tmp >= 52218 And tmp <= 52697 Then 
                getpychar = "T" 
            End If 
            If tmp >= 52698 And tmp <= 52979 Then 
                getpychar = "W" 
            End If 
            If tmp >= 52980 And tmp <= 53640 Then 
                getpychar = "X" 
            End If 
            If tmp >= 53689 And tmp <= 54480 Then 
                getpychar = "Y" 
            End If 
            If tmp >= 54481 And tmp <= 55289 Then 
                getpychar = "Z" 
            End If 
            Return getpychar 
        Else 
            Return hz 
        End If 
    End Function 'hz2py 
Public Function transpy(strhz As String) As String 
   Dim strtemp As String = "" 
   Dim strlen As Integer = strhz.Length 
   Dim i As Integer 
   For i = 0 To strlen - 1 
      strtemp += hz2py(strhz.Substring(i, 1)) 
   Next i 
   Return strtemp 
End Function 'transpy
查表法 感激,再多点意见,谢谢! 这就很全了~ 你帮忙改成VB6的吧

引用 5 楼 ybh37 的回复:
这就很全了~
本帖最后由 bcrun 于 2011-02-25 19:57:54 编辑 参阅:http://www.vbgood.com/thread-84369-1-1.html
引用 6 楼 dbcontrols 的回复:
你帮忙改成VB6的吧


引用 5 楼 ybh37 的回复:
这就很全了~


小弟入门,弱弱地问下,VB2008和VB6的语法不一样吗? 可以利用Word VBA 请问2楼的兄弟所给出的代码支持哪种字库,GBK的是否支持,像有些汉字“莘,垟……”等字能否获得正确的拼音码?
引用 6 楼 dbcontrols 的回复:
你帮忙改成VB6的吧

引用 5 楼 ybh37 的回复:
这就很全了~
以上利用查表法所得的汉字有限 下载个万能五笔 然后找到其中的汉字拼音对应表文件 把它做成查询数据文件即可
补充:VB ,  基础类
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,