03-01-2012 03:07 PM
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?
Solved! Go to Solution.
03-01-2012 03:12 PM
Quoting from the detailed Help:
A space in format string matches any amount of white space, such as spaces, tabs, linefeeds, and form feeds.
03-01-2012 03:44 PM
Very good. I guess the answer was just about staring me in the face. Thanks for the help.