Notifications
Clear all

[Closed] String (saved array) to array

Trying for some time now, but can’t figure out how to convert a string to array. This string is actually an array stored in user defined object properties as string. Now I would like to read it back and convert it into array.

What would be the best way to do that?

Thanks

5 Replies
 lo1

as long as none of the values in the array contain commas, you could do this:


x="#(\"asddas\",\"dddssds\",123123)" --this is your existing string

new_array=(filterstring (substring x 3 (x.count-3)) ",")
for i=1 to new_array.count do new_array[i]=(execute new_array[i])

edit: geez, am I stupid… you just need to


new_array=execute x

Many thanks. I’m 99% sure I tried this with no luck. Had to have some stupid, stupid mistake.

Thanks again, simple and works, would have skipped this because of my stupidity

Warning Do not do this:

CA = (ArrayVar as string)

After about 10 entries it truncates the string to #(item, item, item, item…). Be sure to build your array ‘by hand’:

stringarray = “#(”
for o in ArrayVar do (format (“%,”) (o as string) to:stringarray)
stringarray += “)”

Won’t work for nested arrays unless you explicitely write a recursive function to do it, but there is danger to the old “as string” system of losing data.

or you could do this:

stringArray = with printAllElements on myArray as string

EDIT: this was in response to Gavin’s post, not the OP’s original problem.

Thanks everybody.