如何得到一个汉字的第一个拼音字母

绝世美人儿
898次浏览
2020年07月28日 22:53
最佳经验
本文由作者推荐

补充近义词-肩胛读音

救命!帮助!help!如何得到一个汉字的第一个拼音字母?
作者:cuizm



我想得到一个汉字的第一个拼音字母,比如, 爱 ,第一个字母就是 Z
mfc_basic 多谢了,!!!
---------------------------------------------------------------

Option Explicit

'在窗口中加两个TEXT控件,一个输入中文,一个显示英文
Private Sub Form_Load()
= "我是中国人"
End Sub

Private Sub Command1_Click()
= GetPY()
End Sub

'获得输入名称的首字拼音
Private Function GetPY(ByVal strParmeter As String) As String
Dim intTmp As String, i As Long

For i = 1 To Len(strParmeter)
intTmp = Asc(Mid(strParmeter, i, 1))

If intTmp < Asc("啊") Then
GetPY = GetPY & "*"
ElseIf intTmp >= Asc("啊") And intTmp < Asc("芭") Then
GetPY = GetPY & "A"
ElseIf intTmp >= Asc("芭") And intTmp < Asc("擦") Then
GetPY = GetPY & "B"
ElseIf intTmp >= Asc("擦") And intTmp < Asc("搭") Then
GetPY = GetPY & "C"
ElseIf intTmp >= Asc("搭") And intTmp < Asc("蛾") Then
GetPY = GetPY & "D"
ElseIf intTmp >= Asc("蛾") And intTmp < Asc("发") Then
GetPY = GetPY & "E"
ElseIf intTmp >= Asc("发") And intTmp < Asc("噶") Then
GetPY = GetPY & "F"
ElseIf intTmp >= Asc("噶") And intTmp < Asc("哈") Then
GetPY = GetPY & "G"
ElseIf intTmp >= Asc("哈") And intTmp < Asc("击") Then
GetPY = GetPY & "H"
ElseIf intTmp >= Asc("击") And intTmp < Asc("喀") Then
GetPY = GetPY & "J"
ElseIf intTmp >= Asc("喀") And intTmp < Asc("垃") Then
GetPY = GetPY & "K"
ElseIf intTmp >= Asc("垃") And intTmp < Asc("妈") Then
GetPY = GetPY & "L"
ElseIf intTmp >= Asc("妈") And intTmp < Asc("拿") Then
GetPY = GetPY & "M"
ElseIf intTmp >= Asc("拿") And intTmp < Asc("哦") Then
GetPY = GetPY & "N"
ElseIf intTmp >= Asc("哦") And intTmp < Asc("啪") Then
GetPY = GetPY & "O"
ElseIf intTmp >= Asc("啪") And intTmp < Asc("期") Then
GetPY = GetPY & "P"
ElseIf intTmp >= Asc("期") And
intTmp < Asc("然") Then
GetPY = GetPY & "Q"
ElseIf intTmp >= Asc("然") And intTmp < Asc("撒") Then
GetPY = GetPY & "R"
ElseIf intTmp >= Asc("撒") And intTmp < Asc("塌") Then
GetPY = GetPY & "S"
ElseIf intTmp >= Asc("塌") And intTmp < Asc("挖") Then
GetPY = GetPY & "T"
ElseIf intTmp >= Asc("挖") And intTmp < Asc("昔") Then
GetPY = GetPY & "W"
ElseIf intTmp >= Asc("昔") And intTmp < Asc("压") Then
GetPY = GetPY & "X"
ElseIf intTmp >= Asc("压") And intTmp < Asc("匝") Then
GetPY = GetPY & "Y"
ElseIf intTmp >= Asc("匝") And intTmp < 0 Then
GetPY = GetPY & "Z"
ElseIf (intTmp >= 65 And intTmp <= 91) Or (intTmp >= 97 And intTmp <= 123) Then
GetPY = GetPY & Mid(strParmeter, i, 1)
Else
GetPY = GetPY & "*"
End If
Next
End Function

---------------------------------------------------------------

爱 ,第一个字母就是 Z
我感觉是A呢~~
---------------------------------------------------------------

/Expert/topic/2004/?temp=.0641138
查表法

根据微软拼音输入法得到拼音的例子:
Option Explicit
Private Const IME_ESC_MAX_KEY = &H1005
Private Const IME_ESC_IME_NAME = &H1006
Private Const GCL_REVERSECONVERSION = &H2
Private Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, lpList As Long) As Long
Private Declare Function ImmEscape Lib "" Alias "ImmEscapeA" (ByVal hkl As Long, ByVal himc As Long, ByVal un As Long, lpv As Any) As Long
Private Declare Function ImmGetConversionList Lib "" Alias "ImmGetConversionListA" (ByVal hkl As Long, ByVal himc As Long, ByVal lpsz As String, lpCandidateList As Any, ByVal dwBufLen As Long, ByVal uFlag As Long) As Long
Private Declare Function IsDBCSLeadByte Lib "kernel32" (ByVal bTestChar As Byte) As Long
Public Function GetChineseSpell(Chinese As String, Optional Delimiter As String = " ", Optional IMEName As String = "微软拼音输入法", Optional BufferSize As Long = 255) As String
If ((Chinese)) > 0 Then
Dim i As Long
Dim s As String
s = (BufferSize)
Dim IMEInstalled As Boolean
Dim j As Long
Dim a() As Long
ReDim a(BufferSize) As Long
j = GetKeyboardLayoutList(BufferSize, a(LBound(a)))



For i = LBound(a) To LBound(a) + j - 1
If ImmEscape(a(i), 0, IME_ESC_IME_NAME, ByVal s) Then
If (IMEName) = e((s), (0), "") Then
IMEInstalled = True
Exit For
End If
End If
Next i
If IMEInstalled Then
'Stop
Chinese = (Chinese)
Dim sChar As String
Dim Buffer0() As Byte
'Dim Buffer() As Byte
Dim bBuffer0() As Byte
Dim bBuffer() As Byte
Dim k As Long
Dim l As Long
Dim m As Long
For j = 0 To (Chinese) - 1
sChar = (Chinese, j + 1, 1)
Buffer0 = v(sChar, vbFromUnicode)
If IsDBCSLeadByte(Buffer0(0)) Then
k = ImmEscape(a(i), 0, IME_ESC_MAX_KEY, Null)
If k Then
l = ImmGetConversionList(a(i), 0, sChar, 0, 0, GCL_REVERSECONVERSION)
If l Then
s = (BufferSize)
If ImmGetConversionList(a(i), 0, sChar, ByVal s, l, GCL_REVERSECONVERSION) Then

bBuffer0 = v(s, vbFromUnicode)
ReDim bBuffer(k * 2 - 1)
For m = bBuffer0(24) To bBuffer0(24) + k * 2 - 1
bBuffer(m - bBuffer0(24)) = bBuffer0(m)
Next m
sChar = (v(bBuffer, vbUnicode))
If (sChar, vbNullChar) Then
sChar = ((sChar, (sChar, vbNullChar) - 1))
End If
sChar = (sChar, (sChar) - 1) & (j < (Chinese) - 1, Delimiter, "")

End If

End If
End If
End If
GetChineseSpell = GetChineseSpell & sChar
Next j
Else


End If

End If
End Function

Private Sub Command1_Click()
GetChineseSpell("你好")
End Sub

---------------------------------------------------------------

厉害
学习
关注

---------------------------------------------------------------

学习
---------------------------------------------------------------

mark
---------------------------------------------------------------

如果是数据库中的处理,可以参考SQL数据库对拼音的处理:

/Expert/topic/2361/?temp=.5148279
---------------------------------------------------------------

cuizm(射天狼)的回答不错,以前我的做法是做一个数据库(利用UCDOS里的编码)

---------------------------------------------------------------

赶快收藏中。。。。。。。。。。。。。。
---------------------------------------------------------------

呵呵,不错

征蓬出汉塞-将信将疑


根号2等于多少-技俩


六艺指什么-美食拼音


关联矩阵-清廉的意思


波澜壮阔的近义词-教诲的反义词


lead是什么意思-清点


h1ni-忽略拼音


无规矩不成方圆下一句-婵娟意思