要求函数的功能是:从参数 str 字符串中删除所有参数 ch 所指定的字符,返回实际删除字符的个数,删除后的字符串仍在 str 中,为此某人编写了函数 DelChar 如下: Function DelChar(str As String, ch As String) As Integer Dim n%, st$, c$ st = "" n = 0 For k = 1 To Len(str) c = Mid(str, k, 1) If c = ch Then st = st & c Else n = n + 1 End If Next k str = st DelChar = n End Function 并用下面的 Command1_Click() 过程观察函数调用结果 Private Sub Command1_Click() ch$ = Text1.Text Print DelChar(ch, "x"), ch End Sub 发现结果有错误 , 程序代码需要修改 , 以下正确的修改方案是 ________ 。
举一反三
- 设有如下函数:Function DelSpace(ch As String)As Integer Dim n%, st$, c$ st="" n=0 For k=1 To Len(ch) c=Mid(ch, k, 1) If c[]" " Then st=st & c Else n=n+1 End If Next k ch=st DelSpace=nEnd Function函数的功能是( )。 A: 统计并返回字符串ch中字符的个数 B: 删除字符串ch中的空格符,返回删除字符的个数 C: 统计并返回字符串ch中非空格字符数 D: 删除字符串ch中除空格符外的其他字符,返回删除字符的个数
- 下面程序的输出结果是 Private Sub Command1_Click() ch$="ABCDEF" proc ch Print ch End Sub Private Sub proc(ch As String) S="" For k=Len(ch) To 1 Step-1 s=s & Mid(ch,k,1) Next k ch=s End Sub
- 下面程序运行时,若输入“Visual Basic Prograrmming”,则在窗体上输出的是( ) Private Sub Command1_Click() Dim count(25)As Integer,ch As String ch=Ucase(InputBox("请输入字母字符串")) For k=1 To Len(ch) n=Asc(Mid(ch,k,1))-Asc("A") If n>=0 Then count(n)一count(n)+1 End If Next k m=count(0) For k=1 To 25 If m<count(k) Then m=count(k) End If Next k Print m End Sub A: 0 B: 1 C: 2 D: 3
- 下面程序的输出结果是( )Private Sub proc(ch As String) s = "" For k = Len(ch) To 1 Step -1 s = s & Mid(ch, k, 1) Next k ch = sEnd SubPrivate Sub Command1_Click() ch$ = "ABCDEF" proc ch Print ch End Sub A: ABCDEF B: A C: FEDCBA D: F
- 设有如下事件过程:Private Sub Command1_Click() ch = "ABCDEFG" n = Len(ch) k = 1 Do Print Mid(ch, k, 1); Mid(ch, n, 1); k = k + 1 n = n - 1 Loop Until k > nEnd Sub运行此过程所产生的输出是 A: AGBFCEDD B: AGBFCED C: GFEDCBA D: GAFBECD