设有下面程序代码: Private Sub Command1_Click() Dim str As String, ch As String str = "Visual Basic Programming" ch = "a"

admin2015-08-28  28

问题 设有下面程序代码:
Private Sub Command1_Click()
    Dim str As String, ch As String
    str = "Visual Basic Programming"
    ch = "a"
    n = fun(ch, str)
    Print str, n
End Sub
Private Function fun(ch As String, str As String) As Integer
    Dim strbuf As String, c As String, n As Integer
    For k = 1 To Len(str)
        c = Mid$(str, k, 1)
        If c <> ch Then
            strbuf = strbuf & c
        Else
            strbuf = strbuf & UCase(c)
            n = n + 1
        End If
    Next k
    str = strbuf
    fun = n
End Function
程序运行时的输出是

选项 A、Visual Basic Programming     0
B、VisuAl BAsic ProgrAmming     3
C、Visul Bsic Progrmming     3
D、VisualBasicProgramming     2

答案B

解析 Mid$(A$,4,2)是为了与老版本的VB兼容($的作用是强制将函数的返回值设为字符型)。&用来连接字符串。If条件判断字符是否和输入的字符相等,相等则n加1。选B)。
转载请注明原文地址:https://jikaoti.com/ti/IeJ0FFFM
0

最新回复(0)