VB算法:从字母数字组成的字符串中找出所有大写字母,并逆序输出。 越简单越好。
发布网友
发布时间:2022-05-23 22:57
我来回答
共4个回答
热心网友
时间:2024-03-09 21:15
假设你的字符串已经在变量s里面了:
Sub 按字符逆序输出大写字母()
Dim i As Integer, s As String
Dim x As Integer, c As String
Dim arr(1 To 26) As Integer
s = InputBox("输入字符串")
For i = 1 To 26
arr(i) = 0
Next i
For i = 1 To Len(s)
c = Mid(s, i, 1)
If c >= "A" And c <= "Z" Then
x = Asc(c) - Asc("A") + 1
arr(x) = arr(x) + 1
End If
Next i
c = ""
For i = 26 To 1 Step -1
If arr(i) > 0 Then c = c & Chr(Asc("A") + i - 1)
Next i
MsgBox "你的字符串中出现的大写字母有:" & c
End Sub
热心网友
时间:2024-03-09 21:15
这就是最简单的方式
Private Sub Form_Load()
a = "a23BaC32D*weEF"
For i = Len(a) To 1 Step -1
stra = Mid(a, i, 1)
If stra <= "Z" And stra >= "A" Then aa = aa & stra
Next
MsgBox aa
End Sub
追问呃……仅仅是算法就这么多么?
追答
是啊 从最后一个开始读 ,满足条件就保留,最后倒序输出
热心网友
时间:2024-03-09 21:16
假设你的字符串已经在变量s里面了:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Sub 按字符逆序输出大写字母()
Dim i As Integer, s As String
Dim x As Integer, c As String
Dim arr(1 To 26) As Integer
s = InputBox("输入字符串")
For i = 1 To 26
arr(i) = 0
<a href="https://www.baidu.com/s?wd=Next&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLPhRznAfvPHuhPyDkm1RY0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7gPYpyq8Q1D1PWT3rjTdrH6znHm3nHTsnHb" target="_blank" class="-highlight">Next</a> i
For i = 1 To Len(s)
c = Mid(s, i, 1)
If c >= "A" And c <= "Z" Then
x = Asc(c) - Asc("A") + 1
arr(x) = arr(x) + 1
End If
<a href="https://www.baidu.com/s?wd=Next&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLPhRznAfvPHuhPyDkm1RY0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7gPYpyq8Q1D1PWT3rjTdrH6znHm3nHTsnHb" target="_blank" class="-highlight">Next</a> i
c = ""
For i = 26 To 1 Step -1
If arr(i) > 0 Then c = c & Chr(Asc("A") + i - 1)
<a href="https://www.baidu.com/s?wd=Next&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLPhRznAfvPHuhPyDkm1RY0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7gPYpyq8Q1D1PWT3rjTdrH6znHm3nHTsnHb" target="_blank" class="-highlight">Next</a> i
MsgBox "你的字符串中出现的大写字母有:" & c
End Sub
热心网友
时间:2024-03-09 21:17
Private Sub Command1_Click()
Dim s As String, t As String
Dim slen As Integer
s = InputBox("请输入串")
slen = Len(s)
For i = 1 To slen
m = Mid(s, i, 1)
If m >= "A" And m <= "Z" Then t = m & t
Next
Print t
End Sub