Re: Weeding out words
Re: Weeding out words
- Subject: Re: Weeding out words
- From: Matthew Smith <email@hidden>
- Date: Thu, 08 Feb 2007 17:53:29 +1100
- Thread-topic: Weeding out words
Title: Re: Weeding out words
on 08/02/2007 17:38, Brett Conlon at email@hidden wrote:
Hi all,
I have written a "cleanup" handler to search for words within the text returned in a user dialog. However, it is stripping too much and I'm looking for assistance to help me clean up my cleanup. ;-D
Here's what I've written so far:
set TitleAns to "My Collection box set asset boxy dog box collection is here" -- some example text returned in a user dialog
set Offenders to {"collection", "box", "set", "boxset"} -- words which need to be stripped if the user entered them by mistake.
repeat 5 times --5 times stops endless repeating if any below offending words aren't separated by a space
set storedDelimiters to AppleScript's text item delimiters
set OffenderItems to Offenders's items
repeat with i in OffenderItems
if TitleAns contains i then
set i to (" " & i)
set AppleScript's text item delimiters to i
set TitleAns to TitleAns's text items
set AppleScript's text item delimiters to ""
set TitleAns to TitleAns as Unicode text
set AppleScript's text item delimiters to storedDelimiters
else
exit repeat
end if
end repeat
end repeat
log TitleAns
result: (*My assety dog is here*)
I guess because I'm using text item delimiters to isolate offending words it is finding them inside other words and messing up those that are supposed to be there.
Your help is most appreciated!
How about this?
set TitleAns to "My Collection box set asset boxy dog box collection is here" -- some example text returned in a user dialog
set Offenders to {"collection", "box", "set", "boxset"} -- words which need to be stripped if the user entered them by mistake.
set wordList to every word of TitleAns
set TitleAns to ""
repeat with oneWord in wordList
if oneWord is not in Offenders then
set TitleAns to TitleAns & " " & oneWord
end if
end repeat
The only problem with it is that if there is any punctuation it would be lost. But if it is a list of words separated by spaces then it works well.
--
Matthew Smith
_______________________________________________
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/mailman//archives/applescript-users
This email sent to email@hidden