Posts: 848
Threads: 177
Joined: Aug 2004
I have found the the variable action command "AddQListValue" which has allowed me to build a string list of a set of values which I can then save into a string list field in a variable driver.  But how can I do the reverse?  I can read the string list field into a GVar, but there seems to be no command that will allow me to extract the Nth token in the list, ideally removing the commas and quotes.  If my list had fixed length strings, I could use "GetSubStr" to extract the values, but as the strings are numbers, they can be of different lengths and so I cannot use absolute index and length.
Am I missing something, or the is this a "Write Always - Read Never" situation.  Is there a work around?
PJG
Posts: 3,415
Threads: 158
Joined: Jan 2006
03-14-2017, 08:28 AM
(This post was last modified: 03-14-2017, 08:30 AM by wuench.)
(03-14-2017, 08:15 AM)pjgregory Wrote: I have found the the variable action command "AddQListValue" which has allowed me to build a string list of a set of values which I can then save into a string list field in a variable driver.  But how can I do the reverse?  I can read the string list field into a GVar, but there seems to be no command that will allow me to extract the Nth token in the list, ideally removing the commas and quotes.  If my list had fixed length strings, I could use "GetSubStr" to extract the values, but as the strings are numbers, they can be of different lengths and so I cannot use absolute index and length.
Am I missing something, or the is this a "Write Always - Read Never" situation.  Is there a work around?
PJG
System::GetNthToken with the Whitespace parameter set to comma seems to work for this....
Code:
LocalVars::AddQListValue(LVar:Test, Value1)
LocalVars::AddQListValue(LVar:Test, Value2)
LocalVars::AddQListValue(LVar:Test, Value3)
System::GetNthToken(%(LVar:Test), ,, 2, LVar:OutVal)
LVar:OutVal = Value2
Posts: 848
Threads: 177
Joined: Aug 2004
Thanks.  That's what I was looking for.  Its just not documented in the new Help system.
PJG
Posts: 40,483
Threads: 491
Joined: Aug 2002
Oops, no one had ever caught that. I'll get it added.
Dean Roddey
Explorans limites defectum
Posts: 848
Threads: 177
Joined: Aug 2004
Wuench - Not quite right
with LVar:Test - "value1", "42","False" then using System:GetNthToken( %LVar(Test),, ,,2, LVar:OutValue)
gives LVar:OutValue = "42"
You need to then use
LocalVars::Strip(LVar:OutValue, ", Complete) to remove the quote characters to end up with LVar:OutValue = 42 which can then be written to a field variable. 
Dean: Maybe this should be mentioned in the documentation unless there is a better way of getting the value.
PJG
Posts: 40,483
Threads: 491
Joined: Aug 2002
That is the expected outcome. It breaks up the string based on the comma. So you get everything between the commas, which would include the quotes if it is a list of quoted values. If it were just a list of comma separated values, then there would be no commas. And of course if there are spaces between the values you would want to strip both spaces and quotes in your case.
Dean Roddey
Explorans limites defectum