04-12-2023 07:30 PM - edited 04-12-2023 07:36 PM
Hello, I'm trying to use the function "Scan from String" with variable order using the syntax element %$ as shown in the example of the following document:
But it's not working, the function is taking the number I use to indicate order as if it was a fixed field width specifier, like if the $ symbol wasn't there.
Does anyone knows what am I missing here?
I'm using this code:
and getting this result
I'd appreciate any help on this
Thanks
LabVIEW Professional Development System
Version 2022 Q3 (32-bit) 22.3.1f8
Solved! Go to Solution.
04-12-2023 08:52 PM
That example is meant to be used with Format Into String VI.
What are you trying to achieve with that syntax?
04-12-2023 09:53 PM
As @ZYOng notes, you mixed up "Format into String" (which has an initial String input, and places at the bottom to wire in other values you want to add to the String, specifying the Format for these (presumably non-string, usually numeric or Time) inputs) and "Scan from String" which extracts data from a String input, with the data types specified by the lower terminals, and the Format String specifying how to interpret the contents of the input String.
When I was learning LabVIEW, I found parsing String with the many Number/String conversion functions, confusing and difficult, until I stumbled on Scan from String, which I use whenever I need to parse a String. I have never used the Variable Order format specifier (%$), and I would urge you also to never use it -- it works, but it obscures what you really want to do, namely invert the order of the names. Much better is to explicitly reorder the outputs on the "output side". See if you don't agree that this is easier to code, and easier to understand what it does:
As I was creating this Snippet, I idly wondered how I would parse "Smith, John". This led me to think how I would parse a "Comma-separated-variable" string (where commas separate fields). Turns out (as I was saving the Snippet above) I had another Snippet "Scan String with commas" that I had forgotten about (I posted this in 2019). Here's a hint -- Scan from String is the second function that you need before scanning "Smith, John".
Bob Schor
04-13-2023 10:38 AM
Thanks, I'm reading many data from XML files and building an array with all the data, I want to ensure that all data coming from XML files will always be in the same specific order so I can be sure that each data value is always in the same index position of the array even if the data is in different order across different XML files. When reading the XML file I get a string and I was hoping I could use the Scan from String function to get and order all my data prior to building an array with it.
Thanks, now I know Scan from String function might not be the way to achieve what I'm trying to do.
04-13-2023 11:11 AM - edited 04-13-2023 11:13 AM
Thanks @Bob_Schor, I think you are referencing this snippet, I found it in your profile pictures from 2019. Thanks
04-13-2023 11:30 AM
@ArturoCarranzaFMC wrote:
Thanks, I'm reading many data from XML files and building an array with all the data, I want to ensure that all data coming from XML files will always be in the same specific order so I can be sure that each data value is always in the same index position of the array even if the data is in different order across different XML files. When reading the XML file I get a string and I was hoping I could use the Scan from String function to get and order all my data prior to building an array with it.
Thanks, now I know Scan from String function might not be the way to achieve what I'm trying to do.
I'm not quite sure I understand the issue. If you parse the XML values in the same order, don't they get put into the string in the same order?
04-13-2023 01:01 PM
Thanks for your interest, I'm working on a modular software which requires to accomplish an extensive process for verification and validation, it also requires frequent updates usually for configurations, each update requires to be verified and validated, which takes months. Even if the software is changed in minutes, the verification and validation process takes from weeks to months. So I'm trying to allow the software to work with current and future XML structures so most updates could be limited only to add data into XML files. I was thinking that could save some steps by scanning the result string from the XML, but I think I'll have to use the specific XML parser functions. I appreciate everyone comments it was really helpful, since the original issue is about the Scan from String function using the Variable Order syntax, I think that specific question is already answered by explaining that it is not meant to be used in the Scan from String function, but in the Format into String function.
Thank you all
04-13-2023 01:07 PM
@ArturoCarranzaFMC wrote:
Thanks for your interest, I'm working on a modular software which requires to accomplish an extensive process for verification and validation, it also requires frequent updates usually for configurations, each update requires to be verified and validated, which takes months. Even if the software is changed in minutes, the verification and validation process takes from weeks to months. So I'm trying to allow the software to work with current and future XML structures so most updates could be limited only to add data into XML files. I was thinking that could save some steps by scanning the result string from the XML, but I think I'll have to use the specific XML parser functions. I appreciate everyone comments it was really helpful, since the original issue is about the Scan from String function using the Variable Order syntax, I think that specific question is already answered by explaining that it is not meant to be used in the Scan from String function, but in the Format into String function.
Thank you all
Oh, got it! I didn't realize you were just doing a straight text read and not using an actual XML parser. Thanks for clarifying. V&V, needs to be done, but it sure is a pain.
04-13-2023 01:14 PM
@ArturoCarranzaFMC wrote:
I appreciate everyone comments it was really helpful, since the original issue is about the Scan from String function using the Variable Order syntax, I think that specific question is already answered by explaining that it is not meant to be used in the Scan from String function, but in the Format into String function.
The Variable Order syntax works just fine in Scan from String -- I just recommend not using it, and "interchanging the wires" on the output side, as it is much easier to understand (and hard to find an explanation for what $ means in a Format String specification.
Bob Schor
04-13-2023 01:35 PM
Hi @Bob_Schor, I'm not sure I understand, so my code with Scan from String should work? If it could work it would be easier to edit the format specifier from an external source so I wouldn't need any change to my code and I could have it easy on the verification and validation. Swapping wires it's a change in the code so I would need to update requirements and test procedures, elaborate a test report, organize a design review and document it just to swap the wires, it would take from weeks to months, so it's much easier if I could swap data just by updating an external source without any code modification.