• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to get Pattern Count of variable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >How to get Pattern Count of variable (From: Dan Doughtie <email@hidden>)

  • Prev by Date: Re: Name only of app
  • Next by Date: Re: Filemaker Script
  • Previous by thread: How to get Pattern Count of variable
  • Next by thread: Flattening Nested Lists
  • Index(es):
    • Date
    • Thread