Search returns total number of matches?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
heyvern
Posts: 30
Joined: Sun Feb 21, 2010 12:38 am

Search returns total number of matches?

Post by heyvern » Sat Mar 13, 2010 11:09 pm

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.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Search returns total number of matches?

Post by Mark » Sun Mar 14, 2010 12:34 am

heyvern,

Code: Select all

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

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply