Page 1 of 1

Occurrences

Posted: Tue Jul 06, 2010 1:05 am
by kessingb
I would love a built in function that counts the number of occurrences of some string in a variable/field of text

Re: Occurrences

Posted: Tue Jul 06, 2010 7:25 am
by Curry
Good idea! But it only takes 3 lines of code to do it now. (Well, it can be done in 1 line, but that method might run just a bit slower.)

Re: Occurrences

Posted: Fri Jul 09, 2010 9:03 am
by jmburnod
Kessingb,

If i understand what you want, you can try this script

Code: Select all

function NbOccurInTexte psearch,pCont
   put 0 into rNbOccurInTexte
   put 0 into tCharsToSkip
   repeat
      put offset(psearch, pCont, tCharsToSkip) into UneOcc
      if UneOcc = 0 then exit repeat
      add UneOcc to tCharsToSkip
      add 1 to rNbOccurInTexte
   end repeat
   return rNbOccurInTexte
end NbOccurInTexte
regards
Jean-Marc

Re: Occurrences

Posted: Mon Jul 12, 2010 10:04 pm
by dunbarx
Curry.

I use a short function very similar to the one offered by jmburnod. It gives me the number and locations of a string in a pile of data.

Three lines (or one long one?) sounds like there is a native "allOccurrances" sort of gadget in Rev.

Is there?

Craig Newman