×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Xojo
Posted by: Radium Kymist
Added: Feb 7, 2015 1:02 PM
Views: 24
Tags: no tags
by simulanics

Finds the number of occurrences of a string within another string
  1.  '---  FINDS THE NUMBER OF OCCURENCES OF A STRING WITHIN ANOTHER STRING
  2.  '---  USES THE NATIVE INSTR() FUNCTION
  3.  '---  CASE INSENSITIVE
  4.  '---
  5.  '---  Syntax:  if Occurs(cSearchFor As String,cSearchWithin As String) > 0 then
  6.  
  7.   dim x as Integer = 0
  8.   dim nStart As Integer = 1
  9.   dim nFound as Integer = 0
  10.  
  11.   while nStart < len(cSearchWithin)
  12.     x = instr(nStart,cSearchWithin, cSearchFor)
  13.     if x > 0 then
  14.       nFound = nFound + 1
  15.       nStart = x + 1
  16.     Else
  17.       Exit
  18.     end
  19.   wend
  20.  
  21.   Return nFound