Re: multiple text delimiters
Re: multiple text delimiters
- Subject: Re: multiple text delimiters
- From: "Gary (Lists)" <email@hidden>
- Date: Tue, 27 Sep 2005 20:39:08 -0400
"Michelle Steiner" wrote:
>
> On Sep 27, 2005, at 2:21 PM, Patrick J. Collins wrote:
>
>> Is there a way to set applescripts text delimiters to more than one
>> character?
>
> You can have a string as delimiters; e.g.,
>
> set applescript's text item delimiters to "abcd"
>
>> Like if I wanted to remove all characters "[" "]" "(" and ")" from
>> a string?
>
> You would have to loop through with each character.
>
> set the target_string to "[this] is (a) (test) (sentence.]"
> set the removal_string to {"]", "[", "(", ")"}
>
> repeat with this_delimiter in the removal_string
> set AppleScript's text item delimiters to this_delimiter
> set the temp_list to the text items of the target_string
> set AppleScript's text item delimiters to ""
> set the target_string to the temp_list as text
> end repeat
> target_string
>
> --> "this is a test sentence."
>
> Theoretically, text item delimiters can be a list of strings, but
> it's never been implemented to do that.
Er?
Sure it's implemented that way. Text item delimiters _is_ a list of
strings, even if only one delimiter string is provided (and, I think, even
when you pass a single string, it's used internally as a list of that
string...but IMBW on that one.)
To achieve the save result as you, all one need do is:
--
set the target_string to "[this] is (a) (test) (sentence.]"
set text item delimiters to {"]", "[", "(", ")"}
item 1 of (text of (text items of target_string))
--> "this is a test sentence."
I use TIDs this way all the time to break out parts of text.
--
Gary
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden