Advertisement
4_2005-2006 String Manipulation #163587

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

एआई सारांश: 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.

सोर्स कोड
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
मूल टिप्पणियाँ (3)
Wayback Machine से पुनर्प्राप्त