题库 高中信息

题干

统计数字子串之和。用VB编写程序,在文本框Text1中输入任意字符串s,统计s中数字字符串的数值和(如输入字符串“ab123dr34fg9de”,则输出 166,即 123+34+9=166),并在Label3输出结果。程序设计界面如下:

Private Sub Command1_Click()
Dim s As String, ch As String
Dim ch2 As String, sum As Double
Dim n As Integer, i As Integer
s = Text1.Text
________
i =" 1:" sum = 0
Do While i <= n
ch =" Mid(s," i, 1)
If ch >= "0" And ch <= "9" Then
________
ch2 =" Mid(s," j, 1)
Do While ch2 >= "0" And ch2 <= "9"
j =" j" + 1
ch2 =" Mid(s," j, 1)
Loop
sum =" sum" + ________
i = j
End If
i =" i" + 1
Loop
Label3.Caption = Str(sum)
End Sub
上一题 下一题 0.99难度 填空题 更新时间:2019-02-28 06:14:21

答案(点此获取答案解析)