VB 将文本框中的汉字按拼音排序
发布网友
发布时间:2023-10-24 05:00
我来回答
共3个回答
热心网友
时间:2024-12-15 04:44
首先将汉字转为Ascii码数组,然后对Ascii码数组排序。再将Ascii码数组转换为字符,大功告成了。
以下代码经测试完全正确。
Dim lASC(j) As Long
Private Sub Command1_Click()
Dim i As Long, j As Long, k As Long
Dim r As Long
Dim fs As String
fs = Text1.Text
j = Len(fs) - 1
ReDim lASC(j)
For i = 0 To j
lASC(i) = Asc(Mid(fs, i + 1, 1))
Next
For i = 0 To j - 1
For k = i + 1 To j
If lASC(i) > lASC(k) Then
r = lASC(i)
lASC(i) = lASC(k)
lASC(k) = r
End If
Next
Next
fs = ""
For i = 0 To j
fs = fs & Chr(lASC(i))
Next
Text1.Text = fs
End Sub
热心网友
时间:2024-12-15 04:45
Private Sub Command1_Click()
a = Len(Text1.Text)
For i = 1 To a - 1
i1 = i
For j = i + 1 To a
If Asc(Mid(Text1.Text, j, 1)) < Asc(Mid(Text1.Text, i1, 1)) Then i1 = j
Next j
If i1 > i Then
d1$ = Mid(Text1.Text, 1, i - 1)
d2$ = Mid(Text1.Text, i, 1)
d3$ = Mid(Text1.Text, i + 1, i1 - i - 1)
d4$ = Mid(Text1.Text, i1, 1)
d5$ = Mid(Text1.Text, i1 + 1, a - i1)
End If
Text1.Text = d1$ + d4$ + d3$ + d2$ + d5$
Next i
End Sub
热心网友
时间:2024-12-15 04:45
可以直接按照汉字的ASCII值,进行大小排序:
例如:
Print Asc("安") < Asc("表")
Print Asc("别") < Asc("称")