Re: How to get Pattern Count of variable
Re: How to get Pattern Count of variable
- Subject: Re: How to get Pattern Count of variable
- From: email@hidden
- Date: Sat, 24 Jan 2009 22:56:02 -0800
In Filemaker there is a pattern count function where if you say
PatternCount (myField; Dan)
It will return how many times Dan occurs in that field.
Is there a simple way to do this in Applescript. I want to be able to
analyze a xml file to make sure the same number of <somebracket> is
matched
by </somebracket>.
Try something like this:
set patternToCount to "LOG"
set textToSearch to "log hog doglog blog clog flogged clogged flog"
set itemCount to my PatternCount(textToSearch, patternToCount)
on PatternCount(sourceText, pattern)
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {pattern}
set countedPattern to count of text items of sourceText
set AppleScript's text item delimiters to oldDelims
return countedPattern - 1
end PatternCount
HTH _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden