Re: Removing characters from a string
Re: Removing characters from a string
- Subject: Re: Removing characters from a string
- From: Kai Edwards <email@hidden>
- Date: Tue, 29 Oct 2002 10:02:09 +0000
on Tue, 29 Oct 2002 00:28:59 -0500, Paul Skinner <email@hidden>
wrote:
>
--Store the current TIDs. To be polite to other scripts.
>
set previousDelimiter to AppleScript's text item delimiters
>
set potentialName to "this/might not.be a legal:name, then again, it
>
could be."
>
set legalName to {}
>
set illegalCharacters to {".", ",", "/", ":"} --Whatever you want to
>
eliminate.
>
--Now iterate through the characters checking them.
>
repeat with thisCharacter in the characters of potentialName
>
set thisCharacter to thisCharacter as text
>
if thisCharacter is not in illegalCharacters then
>
set the end of legalName to thisCharacter
>
end if
>
end repeat
>
--Make sure that you set the TIDs before making the
>
--list of characters into a string.
>
set AppleScript's text item delimiters to ""
>
--Check the name's length.
>
if length of legalName is greater than 32 then
>
set legalName to items 1 thru 32 of legalName as text
>
else
>
set legalName to legalName as text
>
end if
>
--Restore the current TIDs. To be polite to other scripts.
>
set AppleScript's text item delimiters to previousDelimiter
>
return legalName
- or you could do most of it with TIDs, looping through the illegal
characters instead:
---------------------------------------------------
set l to {".", ",", "/", ":"}
set n to "this/might not.be a legal:name, then again, it could be."
set tid to text item delimiters
repeat with i from 1 to count l
set text item delimiters to l's item i
set n to (n as string)'s text items
end repeat
set text item delimiters to tid
set n to n as string
if n's length > 32 then set n to n's text 1 thru 32
n
---------------------------------------------------
Kai
--
email@hidden
email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.