Occurrences

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Post Reply
kessingb
Posts: 1
Joined: Mon Jul 05, 2010 11:03 pm

Occurrences

Post by kessingb » Tue Jul 06, 2010 1:05 am

I would love a built in function that counts the number of occurrences of some string in a variable/field of text

Curry
Posts: 111
Joined: Mon Oct 15, 2007 11:34 pm
Contact:

Re: Occurrences

Post by Curry » Tue Jul 06, 2010 7:25 am

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.)
Best wishes,

Curry Kenworthy

LiveCode Development, Training & Consulting
http://livecodeconsulting.com/

WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Occurrences

Post by jmburnod » Fri Jul 09, 2010 9:03 am

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
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Occurrences

Post by dunbarx » Mon Jul 12, 2010 10:04 pm

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

Post Reply