Is there a way I can get the amount of a string is in another string?
Example:
Finding “my” in “My pie is made by my machine. My pie is great!” would return 3 because “my” is in the string 3 times.
Is there a way I can get the amount of a string is in another string?
Example:
Finding “my” in “My pie is made by my machine. My pie is great!” would return 3 because “my” is in the string 3 times.
on tidStuff(paramHere, textHere)
set OLDtid to AppleScript's text item delimiters
set AppleScript's text item delimiters to paramHere
set theItems to text items of textHere
set AppleScript's text item delimiters to OLDtid
return theItems
end tidStuff
set s to "My pie is made by my machine. My pie is great!"
set theCount to (count of tidStuff("My", s)) - 1
Thanks. How reliable would this be?
on countin(F, C)
set Z to AppleScript's text item delimiters
set AppleScript's text item delimiters to F
set theItems to text items of C
set AppleScript's text item delimiters to Z
return theItems
end countin
set s to do shell script "curl [url=http://twitter.com/usernamehere]http://twitter.com/usernamehere"[/url]
if s is not "<html><body>You are being <a href=\"http://twitter.com/suspended\">redirected</a>.</body></html>" and s does not contain "<h2>Sorry, that page doesn't exist!</h2>" then
set thedata to countin("<span class=\"vcard\">\r <a href=\"/", s)
set thelist to false
if (count of thedata) is not 1 then set thelist to items 2 thru end of thedata
if thelist is not false then
set theCount to (count of thelist) - 1
set thefollows to {}
repeat with i in thelist
set thefollows to thefollows & item 1 of countin("\" class=", i)
end repeat
thefollows
end if
end if
P.S. I saw the post on Apple’s website about Flash on Macs and mobile devices. I really understand him.
What are you wanting to accomplish?
Oops. I wanted to make it return a list of the user’s followings. (The people you follow)
This will get the first 100 people the user is following. See the Twitter API to learn how to use the cursor position to get the rest.
I know this is an AppleScript site but writing this in AppleScript would be painful so here is a Ruby example.
Rather academically, given the way this thread has progressed, it’s not necessary to extract text elements physically if you only want to count them. count can count them in situ in the source text.
on countInstances(thisPhrase, theText)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to thisPhrase
set c to (count theText's text items) -- = 'count theText each text item'
set AppleScript's text item delimiters to astid
return c - 1
end countInstances
set s to "My pie is made by my machine. My pie is great!"
countInstances("My", s)
I would rather use Craig’s method because I don’t need to do the line more than once, I get the list, count it, then use the already counted list to process the list of people someone follows on Twitter.
Yes. That’s why I said my contribution was academic. But it’s relevant in the context of your original query.