VB中输入4个字符组成字符串,对该字符串中的字符按ascii码值升序排列后输出,这该怎么编程?

2024-11-16 18:09:25
推荐回答(1个)
回答1:

Private Sub Command1_Click()
Dim s As String
Dim i As Integer, j As Integer, t As Integer
Dim ascS(4) As Integer
s = InputBox("请输入4个字符")
If Len(s) > 4 Then s = Mid(s, 1, 4)
For i = 1 To 4
ascS(i) = Asc(Mid(s, i, 1))
Next

For i = 1 To 3
For j = i + 1 To 4
If ascS(i) > ascS(j) Then
t = ascS(j)
ascS(j) = ascS(i)
ascS(i) = t
End If
Next
Next
s = ""

For i = 1 To 4
s = s + Chr(ascS(i))
Next
MsgBox s
End Sub