LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan from string and blank fields

Hi folks,

I have a file I need to parse with key value pairs set up on individual lines. The keys are not unique. A set of ten repeats with a blank line in between.

 

For some of the keys, a blank value is reasonable.

 

So for instance one time the Key Foo might look like this

Foo =

 

The next it might look like this

Foo = VeryInterestingData

 

So if I use Scan from String with a config string of "Foo = %s" and the value happens to be blank, I get error 85.

 

So, is there a case where error 85 does not mean simply that the field is blank? If not, then the answer is obviously to trap error 85 and write a blank to the output.

 

If there are other reasons why 85 might trip it seems better to somehow precheck for an empty field and if it is empty not perform the scan. But I wasn't able to think of a clever way to do this that wasn't so involved you might as well not use Scan From String and just parse it with the other string manipulation tools.

0 Kudos
Message 1 of 4
(1,685 Views)

Match pattern comes to mind if you always have an equal sign in your lines.

 

Frozen_1-1638389010455.png

 

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
0 Kudos
Message 2 of 4
(1,659 Views)

%s will match anything, so if you get an error 85 using %s you can be pretty sure it is empty.

The other option is, if you know exactly what the key is (as suggested by your scan string), you could just split the string after that many characters.

0 Kudos
Message 3 of 4
(1,616 Views)

As recommended the Match Pattern for the equal sign could be a solution. Another option is to use the pattern "%[^=]=%[^\r\n]" if your line is guaranteed to not be the last line in the string. If it is and your parameter value is empty you would still get the error 85, but errors in LabVIEW are something that can be ignored if you have thought about it well enough, especially if you ignore very specific errors only. They are pretty much never things that will crash your program if you continue anyways (but can of course prevent code further downstream from ever executing successfully).

 

The first pattern will return the Keyword, the second the reminder of the line without any line feed or carriage return. This will include the possible spaces however.

 

If you want to avoid the spaces around the equal sign you could make the pattern:

 

"%[^\s\t=]%[\s\t=]%[^\r\n]"

 

and ignore the second parameter result and just use the first and third.

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 4
(1,600 Views)