Primary command used to split a line of data with multiple values into individual variables. Data is parsed based on a defined "delimiter" such as a space, comma or horizontal tab (ASCII 9). The line of data can be a string variable or a specified line read from a file. In rare cases when no delimiter is present in the data line (e.g. hexadecimal data), the chars attribute can be substituted for the delimiter attribute and ComScript will divide the data line into equal length character strings and load each string into the defined variables. Each variable will have a string length (number of chars) equal to the value set by the chars attribute.
Data parsing can be a little tricky so Green Eyes has provided a detailed example profile with the ComScript download called DataLineParse that demonstrates how to parse a variety of data lines.
Users are strongly encouraged to run DataLineParse, and to look at its profile.xml file and the output file to gain a strong understanding of data parsing.
Loadvars is also used to include variables in the profile that are defined in the config.xml file. The config.xml variables are also displayed and/or editable in the Data Interface.
Attributes:
- string: the string of data to parse
- delimiter: the character separating each value in the line
- type: the source of the variables to load - "text" for textfiles, "string" for text strings and "xml" for the
- config.xml file
- line: the integer value for the line of the file to parse (for text files only). This attribute works well inside a
- while loop so ComScript parses a set number of lines from a file
- vars: the list of one or more variables to save the data into separated by commas. Not used with the config.xml file
- multi: "True" to treat multiple instances of the delimiter as a single instance, "False" by default. Very useful
- with space formatted output.
- file: the path of the xml or text file relative to the profile's directory
- chars: The number of ASCII characters to put into each variable when not using a delimiter
Example:
<loadvars file="config.xml" type="xml" />
<loadvars string="1,2,3,4,5" type="string" delimiter="," vars="a,b,c,d,e" />
result: a=1,b=2,c=3,d=4,e=5
<loadvars string="1 20 300 4 50" type="string" delimiter=" " vars="a,b,c,d,e" multi="True" />
ressult: a=1, b=20, c=300, d=4, e=50
<loadvars file="myFile.txt" type="text" delimiter="," line="1" vars="a,b,c,d,e" />
<loadvars file="myFile.txt" type="text" chars="2" line="1" vars="a,b,c,d,e" />
<loadvars string="0F1AFF" type="string" vars="x,y,z" chars="2" />
result: x=0F, y=1A, z=FF