How can I change these variables?

I am still bad with hadling multiple pieces of data. Can someone tell me how to do this? I have a dialog. When I type a phrase, I need to add a “+” symbol between each word, Any ideas?

set x to text returned of (display dialog "what?" default answer "test one two three")
set y to number of words of x
display "test+one+two+three"

i guess the trick is having it do this no matter how namy words are typed

set foo to (do shell script "/bin/echo" & space & quoted form of (text returned of (display dialog "hurrr" default answer "")) & space & "| /usr/bin/sed -e 's/ /+/g'")
return foo

On second thought, you might want to do it this way, since you never know if you’re going to want the original form of the variable in the future:

set foo to (text returned of (display dialog "hurrr" default answer ""))
set bar to (do shell script "/bin/echo" & space & quoted form of foo & space & "| /usr/bin/sed -e 's/ /+/g'")
return bar

But what if the user adds extra spaces by accident? We don’t want something+like++this+++do++we?

set foo to (text returned of (display dialog "hurrr" default answer ""))
set bar to (do shell script "/bin/echo" & space & quoted form of foo & space & "| /usr/bin/sed -e 's/ * /+/g'")
return bar

It’s worth spending a little time playing around with text item delimiters bonedoc, checking the results line by line. It may take a little while - but, eventually, you’ll realise that you have the hang of them.

This should do the trick:

set t to "test one two three"
set d to text item delimiters
set text item delimiters to "+"
set t to t's words as string
set text item delimiters to d
t --> "test+one+two+three"

Yeah, a lot of people don’t realize that contiguous instances of a delimiter get “discarded”, so to speak, when coercing from a list to a string in that operation.

I’d still kill for a real regex engine in AppleScript. :frowning: