Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving and Loading String Lists
#1
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
Reply
#2
(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
Wuench
My Home Theater/Automation Website

[THREAD=5957]BlueGlass CQC Config[/THREAD]
[THREAD=10624]Wuench's CQC Drivers[/THREAD]
Reply
#3
Thanks.  That's what I was looking for.  Its just not documented in the new Help system.

PJG
Reply
#4
Oops, no one had ever caught that. I'll get it added.
Dean Roddey
Explorans limites defectum
Reply
#5
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
Reply
#6
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Question on Parsing a String in a CML Macro kblagron 2 1,898 06-18-2019, 06:21 PM
Last Post: Dean Roddey
  Saving Global Actions RichardU 1 1,642 12-20-2017, 11:18 AM
Last Post: Dean Roddey
  String list in actions znelbok 3 2,855 11-06-2017, 04:10 PM
Last Post: Dean Roddey
  C-Bus driver loading error znelbok 4 3,230 06-16-2017, 01:12 AM
Last Post: znelbok
  Coding lists Ron Haley 5 3,836 02-08-2017, 06:10 PM
Last Post: Ron Haley
  Inserting global variable into command string MikeA 2 2,340 06-26-2016, 10:09 AM
Last Post: MikeA
  CML - Wrapping String Literals wuench 3 2,050 12-12-2015, 03:52 PM
Last Post: Dean Roddey
  parameter not saving for event monitor bbrendon 2 2,092 10-26-2015, 03:55 PM
Last Post: Dean Roddey
  Working with string lists dlmorgan999 13 5,815 05-26-2015, 06:16 PM
Last Post: Dean Roddey
  Converting Int4 to String zra 11 4,872 04-03-2015, 02:19 PM
Last Post: zra

Forum Jump:


Users browsing this thread: 1 Guest(s)