"Hello" becomes "H e l l o " - space between every character in a string returned from a shell script

I do this

set myText to do shell script sh2

which returns Hello World. I then delete the Hello part:

set myText to (characters 7 thru -1 of myText)

and suddenly myText is W o r l d with a space between each character.

I know I have read something about this. It must have something to do with UTF8/unicode but I can’t find whatever it was I read. How do I fix this?

Hi.

It’s not clear how you’re reading your result. But characters 7 thru -1 of myText returns a list of the characters. If you’re coercing this to text and you happen to have left AppleScript’s text item delimiters set to a space, the space will be inserted between each list item in the result.

The safest and most efficient way to extract the substring is
set myText to text 7 thru -1 of myText

1 Like