怎么查在字符串里有几个某字符
vb吧
全部回复
仅看楼主
level 7
tzchf 楼主
2022年12月15日 11点12分 1
level 15
UBound(Split(字符串,字符))
2022年12月15日 11点12分 2
[大拇指]vb数组功能太弱
2022年12月15日 14点12分
@tzchf (Len(字符串) - Len(Replace(字符串, 某字符, vbNullString)) \ Len(某字符)
2022年12月15日 14点12分
@yjryym 一眼没明白,以后再研究[茶杯]
2022年12月15日 15点12分
level 13
'有时在意速度的可以Instr判断,代码多运行速度却很快,封装成函数,一行调用
Private Sub Form_Click()
Debug.Print GetStringCount(p, "我")
End Sub
Private Function GetStringCount(ByVal strText As String, ByVal strFind As String) As Long
Dim dwStartPos As Long, dwCount As Long
dwStartPos = 1
Do
dwStartPos = InStr(dwStartPos, strText, strFind)
If dwStartPos = 0 Then Exit Do
dwCount = dwCount + 1
dwStartPos = dwStartPos + Len(strFind)
Loop
GetStringCount = dwCount
End Function
2022年12月16日 03点12分 5
1