Contrary to what I said previously about parsing into an array being awkward... in fact there is a simple solution for two problems in string packing:
1. You can mix numeric and string values, even strings with spaces if you enclose in quotes.
2. You can loop in a way to chop the packed string into individual items (numbers or strings) and slip each item into its own element in an array!
See an example in the script below titled STRINGPACKING DEMO.GRG for a simple demonstration of tricky parsing…
Bottom line, string-packing and string-unpacking is an efficient way to store a bunch of different values (combining string and numeric) into a single long string variable, when parsed with spaces - which can then be stored and retrieved from the config.ini file using tv_WriteUserString and tv_ReadUserString.
=============================================================================================
Example of parsing technique that lets you mix numeric and variable length string elements:
Code: Select all
// StringPackingDemo.grg
// Svengali © 2018
// (October) 2018 - ver .2
//easily store and retrieve a string combining numeric values and strings (of various lengths) with UserString
Param none
ScriptName = "StringPackingDemo"
// load a single string variable with numbers and strings - note use of single and double quotes AND PARSING SPACES
PackList = 10.5
PackList = PackList" "349
PackList = PackList" BlueJeans"
PackList = PackList" 'May the Force be with you'"
PackList = PackList" 'none'" // 'none' is always used as a terminator in the packed string
tv_warn "Contents of PackList = " PackList
RestofList = "" // remaining list of items
Counter = 1 // Item count
ItemList(0) = 0 // array for Items
While CMP(RestofList,"none") == 0
Parse PackList Item RestofList
ItemList(Counter) = Item
PackList = RestofList
Counter = Counter + 1
END
FOR i = 1 to Counter-1 // loop to display elements which are now in an array
tv_warn ItemList(i)
END