How does one convert a string to an array
<cfscript>
stResult = { strData = "[1,2,3,4,5,6]"
, arInstant = [1,2,3,4,5,6]
};
//stResult.arData = evaluate(stResult.strData); // this does not work
//stResult.arData = evaluate("#stResult.strData#"); // nor does this
writedump(stResult);
</cfscript>
I am trying to get something that looks like arInstant.
Is there a better way than striping the []
, converting to a list, then converting to an array?
evaluate() should generally be avoided (ref: 1, 2, 3). How about trying:
stResult.arData = ListToArray(stResult.strData, "[],");
This is treating the whole string as a list, with possible delimiters of [
and ]
and ,
It should give you an array with 6 elements in it.
Of course, it seems that your stResult.arInstant
already has what you need... what are you trying to do?