Converting characters to strings

As part of a preprocessing filter I’m writing to do fuzzy comparison of strings I copy the characters of a string, modifying or omitting some of them, and then reassemble them afterwards (based on some code I found online). Unfortunately the resulting string is always empty so I’m clearly doing something wrong. The array seems to be correct when I log it and I printed out the class types of everything and they check out so I’m out of ideas.

Rather than include the original code, I’ve written this simpler test case that duplicates the error:

set test_string to "random text"
set chars to characters of test_string -- convert string to characters

set check_string to chars as string -- convert from characters back to string as check, this works

-- copy characters to new array
set new_chars to {}
repeat with c in chars
    copy c to the end of new_chars
end repeat

log new_chars
set new_string to new_chars as string -- convert copied characters to string

display dialog check_string & " " & new_string -- check string is fine, new one is empty

When I run it, the original characters convert to a string properly, but not the copy. Any tips would be appreciated and I apologize if it’s something obvious. Thank you.

Thought to try the test case on my Air running 10.10 and got an error message (unlike the 10.7 system):

I’m not experienced enough for this to shed any light on the situation, unfortunately.


Edit a single instruction and it will work :

copy c's contents to the end of new_chars

You may also use :

repeat with i from 1 to count chars
	copy chars's item i to the end of new_chars
end repeat

but the first scheme is neater.

Yvan KOENIG running Yosemite 10.10.4 in French (VALLAURIS, France) mardi 28 juillet 2015 18:57:11

Thank you! Knew it was something simple like that.