首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
要求函数的功能是:从参数str字符串中删除所有参数ch所指定的字符,返回实际删除字符的个数,删除后的字符串仍在str中,为此某人编写了函数DelChar如下: Function DelChar(str As String, ch As String) As
要求函数的功能是:从参数str字符串中删除所有参数ch所指定的字符,返回实际删除字符的个数,删除后的字符串仍在str中,为此某人编写了函数DelChar如下: Function DelChar(str As String, ch As String) As
admin
2020-04-18
24
问题
要求函数的功能是:从参数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
发现结果有错误,程序代码需要修改,以下正确的修改方案是( )。
选项
A、把语句If c = ch Then 改为If c <> ch Then
B、把语句Print DelChar(ch, "x"), ch改为Print DelChar(ch, "x") :Print ch
C、把语句DelChar = n 改为 DelChar = st
D、删掉语句str = st
答案
A
解析
DelChar函数中,使用For循环,依次取出str字符串中的字符。然后通过if语句判断取出的字符是否为要删除的字符,若不是则将该字符保存到字符串变量st中,若是则将计数变量n的值加1。观察if条件判断语句可知,"If c = ch Then st = st & c else n=n+1"逻辑有错误,应该改为"If c <> ch Then st = st & c else n=n+1"。故选项A正确。
转载请注明原文地址:https://jikaoti.com/ti/swx0FFFM
本试题收录于:
二级VB题库NCRE全国计算机二级分类
0
二级VB
NCRE全国计算机二级
相关试题推荐
在窗体上画一个名称为Command1的命令按钮,并编写如下程序:PrivateTypeRecord IDAsInteger NameAsString*20EndTypePrivateSubCommand1_Click()
窗体上有一个名称为Text1的文本框,一个名称为Command1的命令按钮。要求编写一个程序,统计文本框中0-9各数字字符的个数。某人编写如下程序:PrivateSubCommand1_Click()Dimcount(10)AsInt
在窗体上画一个命令按钮(Name属性为Commandl),然后编写如下事件过程:PrivateSubCommand1_Click()Dima(10)AsInterger,p(3)AsIntergerK=5
在考生目录下有一个工程文件sjt3.vbp,包含了所有控件和部分程序。程序运行时,在文本框中每输入一个字符,则立即判断:若是小写字母,则把它的大写形式显示在标签Labell中;若是大写字母,则把它的小写形式显示在Labell中;若是其他字符,则把该字符直接
为了每秒钟发生一次计时器事件,可以将Interval属性设置为()。
若在窗体模块的声明部分声明了如下自定义类型和数组:PrivateTyperecCodeAsIntegerCaptionAsStringEndTypeDimarr(5)Asrec则下面的输出语句中正确的是( )。
下列针对框架控件的叙述中,错误的是( )。
以下关于VB的叙述中,错误的是()。
随机试题
简述用户家中水质发生白浊的原因。
TheRedCrossis【B1】______organizationwhichcaresforpeoplewhoarein【B2】______ofhelp.AmaninaParishospitalwhonee
Planesmayaccountforonly2percentoftheworld’scarbonemissions,butitisafiguredestinedtorise.Theaviationindust
胃肠减压的目的不包括
内踝高点直上3寸,胫骨内侧面后缘是
尽管采用完全复制法,ETF的收益率与所跟踪指数的收益率往往还会存在跟踪误差。()
建立社会信用体系的支柱是()。
截至2011年末,T市城镇职工基本医疗保险参保人员474.52万人,城乡居民基本医疗保险参保人员498.30万人.城镇职工基本养老保险参保人员458.70万人,城乡居民基本养老保险参保人员97.80万人.失业保险参保职512258.75万人,工伤保险参保
SomepeoplewouldsaythattheEnglishman’shomeisnolongerhiscastle,andthatithasbecomehisworkshop.Thisispartlybe
A、TherearenotenoughseatsinthecarB、Therearcalreadyenoughpeopletoseeheroff.C、Thegirl’sfamilydoesn’tallowhim
最新回复
(
0
)