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.