Page 1 of 1

Search returns total number of matches?

Posted: Sat Mar 13, 2010 11:09 pm
by heyvern
Is there a search or "Match" that can return the total number of matches in a chunk or string? For example, finding the total number of tabs in string? The only way I see is to change the itemDel and count the items:

Code: Select all

put tab&tab&tab&tab into myVar -- just for this explanation. That isn't how the tabs got there. ;)
get matchText(myVar,"(\011+)",tabCount)
if it is true then
   put the itemDel into gOldDel
   set the itemDel to tab
   put the number of items in tabCount into tabCount
   set the itemDel to gOldDel
else
   put 0 into tabCount
end if

answer tabCount -- returns 4
Is there a better way? This way isn't awful.. but... if there is a more "logical" way I would like to know. Also once again... that silly itemDel thing can get confusing. Do I need to do that with the itemDel inside that if then or will it "reset" after? I am never quite sure when to "reset" itemDel and lineDel.

Re: Search returns total number of matches?

Posted: Sun Mar 14, 2010 12:34 am
by Mark
heyvern,

Code: Select all

set the itemDel to tab
put number of items of (myVar & "x") into myNumberOfTabs
Best,

Mark