如何从字符串中查找斜线发生次数

如何从字符串中查找斜线发生次数

本文介绍了如何从字符串中查找斜线发生次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

使用方法以下函数,如 count = CountChrInString(yourString,/)

 '''
'''返回指定字符串中指定字符的计数。
'''
公共函数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)然后
iResult = 0
结束如果

CountChrInString = iResult

结束函数


How can i find the number of Occurences of ( / ) character from the string in VBA Excel Macros.

解决方案

Use the below function, as in 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

这篇关于如何从字符串中查找斜线发生次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 22:00