indexof
来自「字符串的基本操作,搜索字符串中是否包含此字符,代码非常简短,很有实用价值.」· 代码 · 共 25 行
TXT
25 行
PrivateFunctionSplitStringIntoWords() AsInteger
Dim strComplete As String = "This-is a complete sentence."
DimstrWords() As String
DimstrSeparators() AsChar = {" "c, "-"c}
strWords = strComplete.Split(strSeparators)
Dim i As Integer
Fori = 0 To UBound(strWords)
MessageBox.Show(strWords(i))
Next
EndFunction
Private Function FindNumberOfOccurrences() AsInteger
Dim iPos As Integer, iMatch As Integer
Dim strSearchFor As String = "very"
Dim strSearchIn As String = "This is a very very long sentence."
Do iPos = strSearchIn.IndexOf(strSearchFor, iPos)
If iPos <> -1 Then
iMatch += 1
iPos += strSearchFor.Length
EndIf
LoopUntil iPos = -1
MessageBox.Show(iMatch)
EndFunction
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?