View Full Version : String (saved array) to array
doCHtor 06-20-2010, 02:46 PM 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
|
|
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
doCHtor
06-20-2010, 08:30 PM
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 :)
thatoneguy
06-21-2010, 12:56 AM
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.
Gravey
06-21-2010, 01:34 AM
or you could do this: stringArray = with printAllElements on myArray as stringEDIT: this was in response to Gavin's post, not the OP's original problem.
doCHtor
06-21-2010, 03:46 PM
Thanks everybody.
CGTalk Moderation
06-21-2010, 03:46 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.