Charmed Quark Systems, Ltd. - Support Forums and Community
Question on Parsing a String in a CML Macro - Printable Version

+- Charmed Quark Systems, Ltd. - Support Forums and Community (https://www.charmedquark.com/vb_forums)
+-- Forum: General Discussion (https://www.charmedquark.com/vb_forums/forumdisplay.php?fid=3)
+--- Forum: CQC Support (https://www.charmedquark.com/vb_forums/forumdisplay.php?fid=9)
+--- Thread: Question on Parsing a String in a CML Macro (/showthread.php?tid=10853)



Question on Parsing a String in a CML Macro - kblagron - 06-18-2019

I am playing with the Native Echo Smarthome Skill, and had a question on the best way to do this.

I have the following text string:  "{'channel': {'number': '100'}, 'channelMetadata': {}}"

I want to save the number shown (100) into a variable and discard the rest.  What would be the best recommended way to do so in a CML Macro?  I know I can do some splits, strips, and indexes and get to it in 4  or 5 commands, but was curious is there an easier way to capture that?  The Starting point will always be the same, but the number could be 1, 2, or 3 digits long.


RE: Question on Parsing a String in a CML Macro - kblagron - 06-18-2019

My first stab at this was as follows:

                        DataParm.Cut(0,24);
                        DataParm.Split(TmpStr,''',False);

I guess that should suffice, but open for other ideas.


RE: Question on Parsing a String in a CML Macro - Dean Roddey - 06-18-2019

That's just JSON, so use the JSON parser and it'll do all of that for you.