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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SCAN FROM STRING fails with empty quoted strings

Solved!
Go to solution

I'm scanning a long text line withe SCAN FROM STRING.

BadLine.PNG

 

 

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?

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 1 of 7
(3,926 Views)

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...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 7
(3,899 Views)

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....."

Spoiler
Then he had two problems.

"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 7
(3,896 Views)

I'm with Jeff on this one.  You are going to need to use Regular Expressions to do what you want.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(3,882 Views)

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.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 7
(3,871 Views)
Solution
Accepted by topic author CoastalMaineBird

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.

Message 6 of 7
(3,858 Views)

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!

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 7 of 7
(3,850 Views)