From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
06-25-2014 07:38 AM
I'm scanning a long text line withe SCAN FROM STRING.
My problem comes in the first instance of this part: "[^"]"
The string I am scanning has quotes in it - I want to extract the quoted string as one item.
I can't use %s because the string might have spaces within it.
The format string works fine unless the quoted string is empty ("").
I interpret "[^"]" as QUOTE,any number of things that aren't a QUOTE, QUOTE.
Apparently, the "any number" doesn't include zero, as it fails (error 85: data doesn't match format) when the quotes are empty.
What am I missing?
Blog for (mostly LabVIEW) programmers: Tips And Tricks
Solved! Go to Solution.
06-25-2014 09:26 AM
This doesn't answer your question directly, but I have never had a lot of luck using this function with long strings. I will use it for short chunks or perhaps a single value but not for something like what you show. Personal opinion of course, but I have always found it easier to break a long string into shorter segments and deal with each of the bits separately.
Mike...
06-25-2014 09:32 AM
In this case- you are missing a regex.
And yes I heard the one about the programmer that had a problem and thought "I'll use a regex....."
06-25-2014 11:20 AM
I'm with Jeff on this one. You are going to need to use Regular Expressions to do what you want.
06-25-2014 11:50 AM
I have always found it easier to break a long string into shorter segments
Well, of course I did that, but it offers no help. It's not the length of the string that is a problem.
If you try just "[^"]" in a test, and feed it "ABC" or "A" or "The quick brown fox jumps over the lazy dog's back", it works fine.
Feed it "" and it complains.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
06-25-2014 12:24 PM
This confusion arises in RegExes as well, but you hit on the answer: in the Simpsons "Zero is a percent" but in Scan from String nothing is not something. You asked it to match something which is not a quote, and there is nothing there which is not a quote so it complains.
In this situation if I really wanted to keep the convenience of Scan From String I typically would use Search&Replace to replace "" with "\00" before scanning and then treat a string which only contains null as empty.
06-25-2014 12:41 PM
Thanks, Darin. I was already moving in that direction.
It slows down processing, but I can move to where I catch the errors and only do the substitution on those (few) cases where the empty quotes come up.
Thanks!
Blog for (mostly LabVIEW) programmers: Tips And Tricks