LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan From String matches all adjacent white space characters when a scan sequence to match an exact string ends with a space

Solved!
Go to solution

I have recently written some code to parse a string using the Scan from String function.  The string contains some descriptive text as well as some parameters that I want to retrieve from the string.  My approach was use a format string that would match an exact string (the descriptive text), which removes or skips over the exact string and then match a parameter in the input string.  The remaining string contains more data that gets parsed later on. 

 

The problem that I have encountered is that matching an exact string does not seem to work as I would expect if the exact string ends with a space.  In this case, the exact string is matched, plus any other white space characters that immediately follow the exact string.  Let me illustrate by some examples (\ codes are shown).

 

Case 1:  input string = "Line\s1\s\s\nLine\s2"

             format string = "Line\s%d"

             remaining string = "\s\s\nLine\s2"

             Note that the spaces and line feed after "1" are passed to the remaining string in this case.

 

Case 2:  input string = "Line\s1\s\s\nLine\s2"

             format string = "Line\s%d\s"

             remaining string = "Line\s2"

             Note that all the spaces and line feed immediately after "1" are removed and are NOT passed to the remaining string in this case.

 

The behaviour in case 2 is not what I would have expected.  Can anyone comment on this?  I can probably work around this, but would like to understand how the Scan From String function is supposed to work.  Is this a bug?

0 Kudos
Message 1 of 3
(2,647 Views)
Solution
Accepted by topic author cbfsystems

Quoting from the detailed Help:

 

A space in format string matches any amount of white space, such as spaces, tabs, linefeeds, and form feeds.

Message 2 of 3
(2,643 Views)

Very good.  I guess the answer was just about staring me in the face.  Thanks for the help.

0 Kudos
Message 3 of 3
(2,636 Views)