3个回答
展开全部
首先将汉字转为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
以下代码经测试完全正确。
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
展开全部
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
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
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以直接按照汉字的ASCII值,进行大小排序:
例如:
Print Asc("安") < Asc("表")
Print Asc("别") < Asc("称")
例如:
Print Asc("安") < Asc("表")
Print Asc("别") < Asc("称")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询