[Closed] Help! how to convert strings to arrays???
hi, i am tring to convert strings which is imported from a ini file to arrays, but a error tip said ‘unable to convert: “#(“a”)” to type:array, so how to get a arrays value from a ini file??? many thankx!
If you are getting “#(“a”)” out of your INI file then I’d say the problem is with how you are putting the data into your INI file instead of how to get it out. You don’t want to put the array designators #() in the INI file, since an INI file can only hold string data. To convert that back to an array of strings you’ll have to strip off a lot of characters and rebuild it all.
Instead of printing (or formatting) your array to the INI file you should walk through it and only store the array elements to the INI file.
local TestArray = #("a","b","c","d","e") --array of strings
local sToSave = ""
for i = 1 to TestArray.count do
(sToSave += TestArray[i] --add each element to the string
--put a comma between each element but not after the last one
if i != TestArray.count then sToSave += ","
)
-- at this point sToSave should be "a,b,c,d,e"
setINISetting <INI filepath> <section> <key> sToSave
To retrieve that information from your INI file you would do this:
--get the stored data and put it into a string
local sFromINI = getINISetting <INI filepath> <section> <key>
--split sFromINI at each comma found
local TestArray = filterString sFromINI ","
--TestArray will now be #("a","b","c","d","e"),
--just like it was at the start of the previous script.