获取一个字符串中的子字符串出现次数

第一种方法:

Dim iCount, iFound

iCount = 0

iFound = 0

iFound = inStr(iFound + 1, mainStr, subStr)

While iFound <> 0

 iCount = iCount + 1

 iFound = InStr(iFound + 1, mainStr, subStr)

Wend

 

第二种方法:

  iCount = UBound(Split(mainStr, subStr))

 

第三种方法:

  iCount = (Len(mainStr) - Len(Replace(mainStr, subStr, ""))) / Len(subStr)

 

转载于:https://www.cnblogs.com/dushuai/articles/2582666.html

你可能感兴趣的:(获取一个字符串中的子字符串出现次数)