Title: Re: Fixing busted threads?
Paul and Mr Tea have done a great job of giving you a tutorial in all the basic tools you need to do what you want.
I have a couple of "handlers" that may help you generalize things. (I wrote the script "Strip [*] from Subject", by the way.)
to inBetween(firstPart, secondPart, someString)
set a to offset of firstPart in someString
set b to offset of secondPart in (text a thru -1 of someString)
return text (a + (count firstPart)) thru (a + b - 2) of someString
end inBetween
You can use that, for instance, to find everything between "[" and "]":
set s to "Re: [Wallpaper] Don't use red flock"
set listname to my inBetween("[","]",s)
-- "Wallpaper"
Another approach gives you "before" and "after" routines to use as well:
to BetweenStr(firstPart, secondPart, someString)
set lastpart to afterStr(firstPart, someString) -- What follows firstPart
set midpart to beforeStr(secondPart, lastpart)
return midpart
end BetweenStr
to beforeStr(subStr, mainStr)
set od to AppleScript's text item delimiters
set AppleScript's text item delimiters to subStr
set temp to text items of mainStr
set theBefore to item 1 of temp
set theRest to (the rest of temp) as text
set AppleScript's text item delimiters to od
return theBefore
end beforeStr
to afterStr(subStr, mainStr)
set od to AppleScript's text item delimiters
set AppleScript's text item delimiters to subStr
set temp to text items of mainStr
set theRest to item 1 of temp
set theAfter to (the rest of temp) as text
set AppleScript's text item delimiters to od
return theAfter
end afterStr
set s to "Re: [Wallpaper] Don't use red flock"
set a to my beforeStr("[", s)
-- "Re: "
set b to my afterStr("]", s)
-- " Don't use red flock"
set c to my BetweenStr("[", "]", s)
-- "Wallpaper"
