3个回答
展开全部
ayanami365 的思路正确,但是忽略了当S为空的时候这一特殊情况。
写了一个函数给您调用,这样你可以在任意字符串中查找某字符的个数,调用格式CharNum(A,B),其中A是字符串,B是要查找的字符:
Function CharNum(ByVal strInput As String, ByVal strChar As String) As Long
Dim S() As String
If Len(Trim(strInput)) = 0 Then
CharNum = 0
Else
S = Split(strInput, strChar)
CharNum = UBound(S)
End If
End Function
Private Sub Command1_Click()
Dim A As String, C As String
A = "1,2"
C = ","
MsgBox CharNum(A, C)
End Sub
写了一个函数给您调用,这样你可以在任意字符串中查找某字符的个数,调用格式CharNum(A,B),其中A是字符串,B是要查找的字符:
Function CharNum(ByVal strInput As String, ByVal strChar As String) As Long
Dim S() As String
If Len(Trim(strInput)) = 0 Then
CharNum = 0
Else
S = Split(strInput, strChar)
CharNum = UBound(S)
End If
End Function
Private Sub Command1_Click()
Dim A As String, C As String
A = "1,2"
C = ","
MsgBox CharNum(A, C)
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1楼纯粹在胡说八道,楼主给你代码:
在VB中加入一个按钮:
Private Sub Command1_Click()
Dim ss As String
Dim s As Integer
Dim a As Integer
Dim i As Integer
Dim ii As String
Dim sum As Integer
ss = "1,2,3,4,5"
a = Len(ss)
For i = 1 To Len(ss)
ii = Mid(ss, i, 1)
If ii = "," Then
sum = sum + 1
End If
Next
MsgBox CStr(sum)
End Sub
祝楼主成功!
在VB中加入一个按钮:
Private Sub Command1_Click()
Dim ss As String
Dim s As Integer
Dim a As Integer
Dim i As Integer
Dim ii As String
Dim sum As Integer
ss = "1,2,3,4,5"
a = Len(ss)
For i = 1 To Len(ss)
ii = Mid(ss, i, 1)
If ii = "," Then
sum = sum + 1
End If
Next
MsgBox CStr(sum)
End Sub
祝楼主成功!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim s As String
Dim ss() As String
s = "1,2,3,4,5,6,7"
ss = Split(s, ",")
MsgBox UBound(ss)
就是你要的
Dim ss() As String
s = "1,2,3,4,5,6,7"
ss = Split(s, ",")
MsgBox UBound(ss)
就是你要的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询