大家好,请问如何得到汉字拼音的第一个字母。
1.拼音输入,我输入“你好”,得到“NH”,每个字拼音的简写。
我用了一种解决方法是利用区位码,得到汉字拼音的第一个字母,但是它有个问题就是多音字, 如果我输入“重庆”,得到的却是“ZQ”,请问如何解决,是否要自己建数据库,
2.如何得到汉字的第一笔,不用全部,如果能得到更好。是否要连接字库,是不是要自己建立,网上有没有现成的,我用GOOGLE找了很久没有找到。
请高人指教,先谢过了!!!!我用的语言是VB 6.0!
1.拼音输入,我输入“你好”,得到“NH”,每个字拼音的简写。
我用了一种解决方法是利用区位码,得到汉字拼音的第一个字母,但是它有个问题就是多音字, 如果我输入“重庆”,得到的却是“ZQ”,请问如何解决,是否要自己建数据库,
2.如何得到汉字的第一笔,不用全部,如果能得到更好。是否要连接字库,是不是要自己建立,网上有没有现成的,我用GOOGLE找了很久没有找到。
请高人指教,先谢过了!!!!我用的语言是VB 6.0!
'取汉字的拼音简码.
'函数:HzToPY
'参数:HzStr 要取码的字符串.
'返回值:字符串的拼音简码.(如果是英文或数字字符,则原样返回)
'例子:
Public Function HzToPY(HzStr As String) As String
Dim T1 As String, sPy As String, tPy As String
Dim I As Long, j As Long, K As Long, A As Long
Dim strlen As Long, HzAsc As Long
Dim PyChar As String, HzChar As String, PyStr As String
Dim HzNumber As String, EngNumber As String
Dim StrTmp As String, CharTmp As String
Dim NumLen As String, StrNum As Long
Dim Nl As Long, Nsum As Long
Dim CharNum As String, RetuStr As String
Dim HzSun As String, RenFlag As Boolean
Dim NumChar As String, UHZnumber As String
Dim Enumtmp As String, TT As String
'/--------------------------------------------------------
HzStr = Trim$(UCase$(HzStr))
strlen = Len(HzStr)
'/---------------------------------------------------------------------
tPy = "啊芭擦搭蛾发噶哈击喀垃妈拿哦啪期然撒塌挖昔压匝 " '24
sPy = "OABCDEFGHJKLMNOPQRSTWXYZ" '23
For A = 1 To strlen
HzChar = Mid$(HzStr, A, 1)
HzAsc = Asc(HzChar)
If HzAsc >= 0 Then
If (HzAsc <= Asc("Z") And HzAsc >= Asc("A")) Or (HzAsc <= Asc("9") And HzAsc >= Asc("0")) Then
PyChar = HzChar
GoTo GotoNext
Else
PyChar = Chr("0")
GoTo GotoNext
End If
End If
'/---------------------------------------------------------------------
For I = 1 To 23
j = Asc(Mid$(tPy, I, 1))
K = Asc(Mid$(tPy, I + 1, 1))
If I = 1 And Asc(HzChar) < j Then PyChar = "0": GoTo GotoNext
If I = 23 And Asc(HzChar) >= j Then PyChar = "Z": GoTo GotoNext
If HzAsc >= j And HzAsc < K Then
PyChar = Mid$(sPy, I + 1, 1): GoTo GotoNext
End If
Next I
GotoNext:
PyStr = PyStr & PyChar
Next A
HzToPY = PyStr
End Function2.取汉字的第一笔,比较麻烦..留下你的EMAIL.我给你一个类.
取得汉字的拼音首字
用以下的函数可以得到汉字的拼音首字字符,注意:对 噢、杞、
嘌、呤 是个例外。
对很多汉字无法正确的实现转换,
原因是在该程序根据汉字在编码表中的位置来判断的,
而部分的汉字所在的位置有误,所以 。
Public Function GetPY(a1 As String) As String
Dim t1 As String
If Asc(a1) < 0 Then
t1 = Left(a1, 1)
If Asc(t1) < Asc("啊") Then
GetPY = "0"
Exit Function
End If
If Asc(t1) >= Asc("啊") And Asc(t1) < Asc("芭") Then
GetPY = "A"
Exit Function
End If
If Asc(t1) >= Asc("芭") And Asc(t1) < Asc("擦") Then
GetPY = "B"
Exit Function
End If
If Asc(t1) >= Asc("擦") And Asc(t1) < Asc("搭") Then
GetPY = "C"
Exit Function
End If
If Asc(t1) >= Asc("搭") And Asc(t1) < Asc("蛾") Then
GetPY = "D"
Exit Function
End If
If Asc(t1) >= Asc("蛾") And Asc(t1) < Asc("发") Then
GetPY = "E"
Exit Function
End If
If Asc(t1) >= Asc("发") And Asc(t1) < Asc("噶") Then
GetPY = "F"
Exit Function
End If
If Asc(t1) >= Asc("噶") And Asc(t1) < Asc("哈") Then
GetPY = "G"
Exit Function
End If
If Asc(t1) >= Asc("哈") And Asc(t1) < Asc("击") Then
GetPY = "H"
Exit Function
End If
If Asc(t1) >= Asc("击") And Asc(t1) < Asc("喀") Then
GetPY = "J"
Exit Function
End If
If Asc(t1) >= Asc("喀") And Asc(t1) < Asc("垃") Then
GetPY = "K"
Exit Function
End If
If Asc(t1) >= Asc("垃") And Asc(t1) < Asc("妈") Then
GetPY = "L"
Exit Function
End If
If Asc(t1) >= Asc("妈") And Asc(t1) < Asc("拿") Then
GetPY = "M"
Exit Function
End If
If Asc(t1) >= Asc("拿") And Asc(t1) < Asc("哦") Then
GetPY = "N"
Exit Function
End If
If Asc(t1) >= Asc("哦") And Asc(t1) < Asc("啪") Then
GetPY = "O"
Exit Function
End If
If Asc(t1) >= Asc("啪") And Asc(t1) < Asc("期") Then
GetPY = "P"
Exit Function
End If
If Asc(t1) >= Asc("期") And Asc(t1) < Asc("然") Then
GetPY = "Q"
Exit Function
End If
If Asc(t1) >= Asc("然") And Asc(t1) < Asc("撒") Then
GetPY = "R"
Exit Function
End If
If Asc(t1) >= Asc("撒") And Asc(t1) < Asc("塌") Then
GetPY = "S"
Exit Function
End If
If Asc(t1) >= Asc("塌") And Asc(t1) < Asc("挖") Then
GetPY = "T"
Exit Function
End If
If Asc(t1) >= Asc("挖") And Asc(t1) < Asc("昔") Then
GetPY = "W"
Exit Function
End If
If Asc(t1) >= Asc("昔") And Asc(t1) < Asc("压") Then
GetPY = "X"
Exit Function
End If
If Asc(t1) >= Asc("压") And Asc(t1) < Asc("匝") Then
GetPY = "Y"
Exit Function
End If
If Asc(t1) >= Asc("匝") Then
GetPY = "Z"
Exit Function
End If
Else
If UCase(a1) <= "Z" And UCase(a1) >= "A" Then
GetPY = UCase(Left(a1, 1))
Else
GetPY = "0"
End If
End If
End Function
注明:汉字编码.
http://www.onlinedown.net/soft/17761.htm