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

第一种方法:

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)

 

posted @ 2012-07-09 14:25  dushuai  阅读(153)  评论(0编辑  收藏  举报