VB算法:从字母数字组成的字符串中找出所有大写字母,并逆序输出。 越简单越好。
答案:4 悬赏:80 手机版
解决时间 2021-03-31 15:39
- 提问者网友:嘚啵嘚啵
- 2021-03-30 14:41
VB算法:从字母数字组成的字符串中找出所有大写字母,并逆序输出。 越简单越好。
最佳答案
- 五星知识达人网友:不想翻身的咸鱼
- 2021-03-30 16:07
假设你的字符串已经在变量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
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
全部回答
- 1楼网友:山君与见山
- 2021-03-30 18:38
假设你的字符串已经在变量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
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
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
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
- 2楼网友:琴狂剑也妄
- 2021-03-30 18:19
这就是最简单的方式
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追问呃……仅仅是算法就这么多么?追答
是啊 从最后一个开始读 ,满足条件就保留,最后倒序输出
- 3楼网友:往事隔山水
- 2021-03-30 17:01
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
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
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯