这么行不行? Private Sub Command1_Click() Dim strSample As String strSample = "kjoj,ojiljoi,joijig,ojisghd,shgm,hgiwesj,jfk,jij,ifj,ijk,okfsodkf,sdjfsdf,jisjf,jsof,"
Dim lPos As Long Dim lLastPos As Long lLastPos = 0
Dim i As Integer For i = 1 To 7 lPos = InStr(strSample, ",") If lPos = 0 Then lLastPos = 0: Exit For strSample = Mid(strSample, lPos + 1) lLastPos = lLastPos + lPos Next
MsgBox lLastPos
End Sub
俺试过了,这个Function可以:Function searchchar(i_count As Integer, str_searched As String, str_char As String) '----------------------------------------------- 'i_count :制定字符串要求出现的次数 'str_searched :目标字符串 'str_char :被搜索字符串 '----------------------------------------------- Dim i_situation As Integer '----------------------------------------------- i_situation = 0 '----------------------------------------------- For i = 1 To i_count i_situation = InStr(i_situation + 1, str_searched, str_char) Next i searchchar = i_situation End Function
Private Sub Command1_Click()
Dim strSample As String
strSample = "kjoj,ojiljoi,joijig,ojisghd,shgm,hgiwesj,jfk,jij,ifj,ijk,okfsodkf,sdjfsdf,jisjf,jsof,"
Dim lPos As Long
Dim lLastPos As Long
lLastPos = 0
Dim i As Integer
For i = 1 To 7
lPos = InStr(strSample, ",")
If lPos = 0 Then lLastPos = 0: Exit For
strSample = Mid(strSample, lPos + 1)
lLastPos = lLastPos + lPos
Next
MsgBox lLastPos
End Sub
'-----------------------------------------------
'i_count :制定字符串要求出现的次数
'str_searched :目标字符串
'str_char :被搜索字符串
'-----------------------------------------------
Dim i_situation As Integer
'-----------------------------------------------
i_situation = 0
'-----------------------------------------------
For i = 1 To i_count
i_situation = InStr(i_situation + 1, str_searched, str_char)
Next i
searchchar = i_situation
End Function