VB字符处理专题导学案
班级_______________姓名____________
【学习目标】
1、熟悉常用字符串处理函数:len(x)、mid(x,i,k)、str(x)等函数功能及其相关参数的作用
2、灵活运用mid函数,根据要求随意地截取出所需的字符内容
3、熟练掌握字符串的查定位及算法实现程序代码
4、提高将解决问题的思路表现为代码的能力,发展计算思维
【学习过程】
(一)课前准备
1.填空
函数 | 功能 | 应用实例 | 函数返回值 |
Len(x) | 求x的长度 | X=”123”len(x) | |
X=”12 3”len(x) | |||
Mid(s,i,k) | 取出字符串s中第i个字符开始长度为k个字符的子串 | S=”how are you” Mid(s,5,3) | |
Mid(s,i) | 从s字符串中第i个字符开始一直取到底 | S="hi,how are you" Mid(s,4) | |
Str(x) | 将数值x转换为字符串 | X=123 str(x) | |
X=-2454 str(x) | |||
2.有如下VB程序段
Dim s as string
s="hello"
iflen(s)>=5 then
字符串函数 通配符 vb s=mid(s,3,2)
else
s=mid(s,1,2)
end if
该程序段运行后s的值是____________
3.有如下vb程序段
Dim s as string
Dim i as integer,count as integer
s=”hello”
i=1:count=0
do while i<=len(s)
if mid(s,i,1)=”l” then
count=count+1
end if
i=i+1
loop
list1.additem str(count)
该程序段运行后列表框list1中显示的内容是________
(二)课中学习
1.查单个字符:
算法思想:____________________________________________________
完善代码: Private Sub Command1_Click() Dim s As String,c as string Dim n As Integer, i As Integer s = Text1.Text c = Text2.Text n = 0: i = 1 List1.clear Do While i <= Len(s) If ________①_________ Then n = n + 1 List1.AddItem "字符所在位置:" + Str(i) End If i = i + 1 Loop Text3.Text = Str(n) End Sub | |
2.查字符串
算法思想:____________________________________________________
完善代码: Private Sub Command1_Click() Dim s As String, c As String,ch as String Dim i As Integer,n As Integer s = Text1.Text : c = Text2.Text n = 0: i = 1 List2.clear Do While i <= Len(s) _________①___________ If ch = c Then n = n + 1 List1.AddItem "第" + Str(n) + "个字符串的首字符位置" + Str(i) ______②_____ Else i = i + 1 End If Loop Text3.Text = Str(n) End Sub | |
3.查单词
(简易版:单词之间用空格连接)
算法思想:________________________________
完善代码: Private Sub Command1_Click() Dim s As String, c As String,Dim ch As String Dim i As Integer, n As Integer s = Text1.Text:c = Text2.Text n = 0: i = 1 List1.Clear Do While i <= Len(s) ch = Mid(s, i, Len(c)) If ch = c Then If ① Then n = n + 1 List1.AddItem "第" + Str(n) + "个字符串位置" + Str(i) End If i = i + Len(c) Else i = i + 1 End If Loop Text3.Text = Str(n) End Sub |
(三)课堂小结
【学后反思】
1._____________________________________________________________
2._____________________________________________________________
3._____________________________________________________________
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论