Coercion with delimiters

Wouldn’t it be handy if coercion of a list to a string could be done with delimiters rather than by a separate text item operation? i.e.

set AppleScript's text item delimiters to ""
set myList to {"Now", "is", "the", "time"}
set wishString to myList as string with text delimiters space -- which won't work, of course

-- instead of

set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
set ListString to myList as string
set AppleScript's text item delimiters to tid -- which does

Maybe someday…

I would dance!

Try something like this:

myList = Array["Now", "is", "the", "time"] ListString = myList.join(" ")
Wait, that’s a different langauge… Nevermind. :stuck_out_tongue:

“I would dance!” :).

If I have a lot of list to string coercions I use a list to string subroutine with delimiter parameter.

gl,

and I do :smiley: I just dislike seeing code on my screen when I think it shouldn’t have to be there :lol:

How about:

set myList to {"Now", "is", "the", "time"}
set myString to ""
repeat with anItem in myList
	set myString to myString & anItem & " "
end repeat
myString

Oh wait… That’s not any better! And now I have a space at the end of my string. :rolleyes:

Am I missing something?

set AppleScript's text item delimiters to " "
set myList to {"Now", "is", "the", "time"}
myList as string

Nope that works, but in general good practice dictates that you:

¢ Set a variable to the exisiting delimiters
¢ Change the delimiter to what you need
¢ Coerce the strig
¢ Change the delimiters back

So yes, you could do it in two lines (ignoring your myList declaration), but most times it’s bad form.

So the hope is that one day you can do it as adam pointed out all in one statement without worrying about your normal operating delimiters.

set wishString to myList as string with text delimiters space -- which won't work, of course