Re: Removing characters from a string
Re: Removing characters from a string
- Subject: Re: Removing characters from a string
- From: Paul Skinner <email@hidden>
- Date: Tue, 29 Oct 2002 00:28:59 -0500
On Monday, October 28, 2002, at 10:01 AM, Steve Savery wrote:
Oh, sorry. I'd like to remove illegal characters for filenames used in
OS 9. As I am only looking to use the variable to name a folder I'm
not concerned about extensions.
Thanks,
Steve
set potentialName to "this/might not.be a legal:name, then again, it
could be."
set legalName to (characters of potentialName not in {".", ",", "/",
":"}) as text
.
.
.
HAAAA! :D
not really. no. It could never be made to work.
You know. I think I'll do that more. I feel better after typing it.
so, back to reality...
--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
--
Paul Skinner
On Monday, Oct 28, 2002, at 14:23 Europe/London, Paul Skinner wrote:
What exactly do you want? OS 9 legal filenames? OS X? Room for
extensions? Allow current extensions? Remove illegals or replace with
legals?
--
Paul Skinner
On Monday, October 28, 2002, at 08:50 AM, Steve Savery wrote:
How can I remove certain characters (or patterns of characters) from
a string?
I need to check for, and remove, all illegal characters from a
string variable before using it to name a new folder.
Thank you.
Steve
_______________________________________________
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.