VB程序:统计子字符串在原字符串中出现的次数
答案:2 悬赏:0 手机版
解决时间 2021-03-15 13:56
- 提问者网友:辞取
- 2021-03-14 23:50
弄下代码、谢谢~
最佳答案
- 五星知识达人网友:西风乍起
- 2021-03-15 00:57
Private Sub Command1_Click()
If Len(Text1.Text) = 0 Then
MsgBox "请输入原字符串内容:"
Text1.SetFocus
ElseIf Len(Text2.Text) = 0 Then
MsgBox "请输入子字符串内容:"
Text2.SetFocus
Else
Label3.Caption = "子字符串在原字符串中出现了:" & UBound(Split(Text1.Text, Text2.Text)) & "次"
End If
End Sub
If Len(Text1.Text) = 0 Then
MsgBox "请输入原字符串内容:"
Text1.SetFocus
ElseIf Len(Text2.Text) = 0 Then
MsgBox "请输入子字符串内容:"
Text2.SetFocus
Else
Label3.Caption = "子字符串在原字符串中出现了:" & UBound(Split(Text1.Text, Text2.Text)) & "次"
End If
End Sub
全部回答
- 1楼网友:鸽屿
- 2021-03-15 01:06
private sub command1_click()
dim a, b, n
a = "ab"
b = "aekdabf9lab&*&*&^%^$^jlk9uab90klj..jl;"
n = (len(b) - len(replace(b, a, ""))) / len(a)
msgbox a & vbcrlf & " 在 " & vbcrlf & b & vbcrlf & " 中出现了 " & n & "次."
end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯