小智 37
老问题,但我想我会通过在excel论坛上找到的答案来增加答案的质量.显然,计数也可以使用.
count =Len(string)-Len(Replace(string,"/",""))
Run Code Online (Sandbox Code Playgroud)
答案全部归功于原作者:http://www.ozgrid.com/forum/showthread.php?t = 45651
ass*_*ias 17
使用以下功能,如count = CountChrInString(yourString, "/").
'''
''' Returns the count of the specified character in the specified string.
'''
Public Function CountChrInString(Expression As String, Character As String) As Long
'
' ? CountChrInString("a/b/c", "/")
' 2
' ? CountChrInString("a/b/c", "\")
' 0
' ? CountChrInString("//////", "/")
' 6
' ? CountChrInString(" a / b / c ", "/")
' 2
' ? CountChrInString("a/b/c", " / ")
' 0
'
Dim iResult As Long
Dim sParts() As String
sParts = Split(Expression, Character)
iResult = UBound(sParts, 1)
If (iResult = -1) Then
iResult = 0
End If
CountChrInString = iResult
End Function
Run Code Online (Sandbox Code Playgroud)
mar*_*uja 14
Function CountOfChar(str as string, character as string) as integer
CountOfChar = UBound(Split(str, character))
End Function
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
63555 次 |
| 最近记录: |