Advertisement
ASP_Volume3 String Manipulation #58290

StrCount function

Function that counts the occurrance of a given phrase in a larger string. (I needed this function and couldn't find anything like it in MSDN for VB)

AI

KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Quellcode
original-source
Public Function StrCount(ByVal cToSearch As String, ByVal cSearchPhrase As String) As Long
 Dim nDifference As Long  ' The difference in length after the replace
 
 ' Is there anything to search?
 If Len(cSearchPhrase) > 0 Then
  nDifference = Len(cToSearch) - Len(Replace(cToSearch, cSearchPhrase, ""))
  StrCount = nDifference / Len(cSearchPhrase)
 Else
  StrCount = 0
 End If
 
End Function
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine