LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Spaces and Tabs in Scan From String

Solved!
Go to solution

Hi all.  I'm sure this question has been answered before, but I couldn't find exactly what I was looking for.

 

I'm having trouble with the scan from string function.  My format string specifies tabs (\t) as the delimiters between multiple parameters, however it's also using spaces.  As a result, a string which contains spaces causes it to fail on the next parameter because it's expecting a number but sees instead the remainder of the string.

 

Please see the attached.

 

If I replace the spaces with a token (in this case #SPACE#), I can read the string and the numbers correctly.  Then, I have to re-replace the tokens with spaces after reading it back.

 

Therefore, what I'm looking for is a way to specify the tab charater as a delimiter, but not the space character.

 

thanks for your help.

0 Kudos
Message 1 of 9
(6,553 Views)

Instead  of %s use the character set [a-zA-Z0-9 ] (with a space at the end).

 

Ben64

0 Kudos
Message 2 of 9
(6,541 Views)

That doesn't seem to work at all.

 

This is now my full format string:  %f\t%f\t[a-zA-Z0-9 ]\t%f\n

 

The Format Into String is now demanding a double input where the alphanumeric characters should go.

 

The scan from string gives only three outputs, all numeric. 

 

Instead of treating [a-zA-Z0-9 ] as an indicator of a string, it's treating it as a literal string and inserting it as is.

0 Kudos
Message 3 of 9
(6,537 Views)

I forgot to specify, you need to put the % before the character set.

 

Ben64

0 Kudos
Message 4 of 9
(6,535 Views)

That does make a big difference.

 

But what if I want to include all printable characters, not just alphanumerics?

0 Kudos
Message 5 of 9
(6,532 Views)
Solution
Accepted by LandBelenky

I would use %[^\t] in this case, which will read any character that isn't a tab.

0 Kudos
Message 6 of 9
(6,526 Views)

Okay, that seems to work.  But now I'm confused.

 

Why does \t match both tabs and spaces, but ^\t reads spaces but not tabs?

0 Kudos
Message 7 of 9
(6,522 Views)

LandBelenky wrote:

Why does \t match both tabs and spaces, but ^\t reads spaces but not tabs?


It would be more accurate to say that %s doesn't match spaces.  Your original code fails trying to match the tab after the %s.

0 Kudos
Message 8 of 9
(6,518 Views)

Have a look at "Format specifiers" in the LabVIEW help (in index search, format specifiers -> syntax elements).

 

Ben64

0 Kudos
Message 9 of 9
(6,512 Views)