VB里面怎么计算字符串A里有多少个字符串B?

[复制链接]
查看11 | 回复3 | 2013-7-21 15:00:35 | 显示全部楼层 |阅读模式
遍历字符串,每次遍历到字符"7",就在初始值为0的变量i+1以下是代码Module Module1
Sub Main()
Dim strA As String = "777787778967"
Dim i As Integer = 0
For Each strB As String In strA
If strB = "7" Then
i = i + 1
End If
Next
Console.WriteLine("字符串777787778967中共有{0}个7.", i.To...
回复

使用道具 举报

千问 | 2013-7-21 15:00:35 | 显示全部楼层
Private Sub Form_load() Dim a, b As String Dim i, n As Integer a = "777787778967": b = "7" On Error Resume Next For i = 1 To Len(a) If Mid(a, i, Len(b)) = b Then n = n + 1 Next i M...
回复

使用道具 举报

千问 | 2013-7-21 15:00:35 | 显示全部楼层
Dim A As String, B As StringDim N As Integer, iPos As IntegerA = "777787778967"B = "7"Do
iPos = InStr(iPos + 1, A, B)
If iPos = 0 Then Exit Do
N = N + 1 ...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行