用VB编写程序,找出输入字符串中ASCII代码值最大的字符,把它移动到原字符串末尾,其它字符排列顺序不变

来源:百度知道 编辑:UC知道 时间:2024/06/05 00:08:20
用VB编写程序,找出输入字符串中ASCII代码值最大的字符,把它移动到原字符串末尾,其它字符排列顺序不变,例如输入“student”,结果是“stdentu”(若输入字符串中还有多个最大字符,只移动其中的一个)

新建窗体,画两个文本框text1(用于输入),text2(用于输出),一个按钮
command1

然后把代码复制下面的代码点击按钮就可以了(excel——vba中调试通过)

Option Explicit

private Sub command1_click()
Dim i, n, tem As Integer, a, tem2, res As String
a=text1.text
n = 0
For i = 1 To Len(a)
If i = 1 Then
tem = Asc(Mid(a, i, 1))
Else
If tem < Asc(Mid(a, i, 1)) Then
tem = Asc(Mid(a, i, 1))
tem2 = Mid(a, i, 1)
n = i
End If
End If
Next i
If n <> 0 Then
res = Left(a, n - 1) & Mid(a, n + 1, Len(a)) & tem2
Else
res = Right(a, Len(a) - 1) & Left(a, 1)
End If
text2.text=res
End Sub

来自:求助得到的回答