What's wrong with this this form of concatenation?

Hello,

I’m trying to optimize my code a bit, and I read that its faster to add to the end of a list when concatenating. What is wrong with this code? Thanks in advance for reading!

set the_stack to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>

"

set end of the_stack to "<DOCUMENT>" & return

it works if I say:

set the stack to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>

"
set the stack to the_stack & "<DOCUMENT>" & return

Hi,

end of works only with lists or records, not with strings

but you can use

set the_stack to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>

"

set end of the_stack to "<DOCUMENT>"
set {TID, text item delimiters} to {text item delimiters, return}
set the_stack to theStack as text -- concatenats the list to a string with delimiter return
set text item delimiters to TID

If you want line feeds instead of carriage returns:

set {TID, text item delimiters} to {text item delimiters, ASCII character 10}

Thanks guys! I appreciate the clarification and examples.
Best,
Cyan