LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Scanning Ascii file with several data types

Hey,

 

I've a question how to parse an ascii file with a number of these lines:

,100000,0x04fca914,32 ,M,1,OK,N,NULL,N/A [0],Go,N/A [0],0,0,0,,,,9, 00:00:00.006553,2008-10-19 22:33:54.694217 ,

I'm interested in the 1st (int), 4th (string), 9th (sting), 12th (int) and 13th(int) value. I used Scan like

Scan (lineBuffer, "%s>,%i,%s[dt#]%s[t44]%s[t44]%s[t44]%s[t44]%s[t44]%s[t44]%s[t44]%s[t44]%i,%i,%s[t44]",&frame,&buf1,&buf2,&tmpchar2,&buf3,&buf4,&buf5,&buf6,&tmpchar1,&buf7,&buf8,&SEQN,&ARQN);

but when I try to read &SEQN, I get nothing. The same in all other variables excluding the first.

Do anybody have an idee?

 

Thanks,

Martin

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

You are simply missing some little 'x's in your scan modifiers Smiley Wink

When scanning a string, [t44] stops scanning before the comma, next every subsequent instruction remains in the same point in the string, stopping at the same comma Smiley Mad

If you add 'x' to the modifier (i.e. [xt44] )Scan stops at the comma, discards it and starts scanning for the next item after this point.

In situations like yours, I find very useful  NumFmtdBytes (); function, which returns the number of bytes handles by the most recent Fmt or Scan function. In your case, this number was 24, considerably shorter than the expected lenght.

Last hint, when scanning with %s specifier, you do not need '&' operator, since strings are already passed as pointers to the function.

 

After these modifications (and adding two extra strings discarded to match your requirements as of the number of parameters scanned) the resulting instruction is this one:

 

Scan (msg, ",%d[x]%s[xt44]%s[xt44]%s[xt44]%s[xt44]%s[xt44]%s[xt44]%s[xt44]%s[xt44]%s[dxt44]%s[dxt44]%i[x]%i[x]%s[xt44]",
    &frame, buf2, tmpchar2, buf3, buf4, buf5, buf6, tmpchar1, buf7, &buf8, &SEQN, ARQN);

 

NumFmtdBytes returns 62 after this line.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,393 Views)

Thanks, now it works.. But I've a second question. When I parse my log file i get some strange results

if there are blank spaces. Is there a method to ignore them?

 

Greetings and thx

Martin

0 Kudos
Message 3 of 4
(3,369 Views)

Which exact anomaly are you experiencing? Using a correct scan string and provided the appropriate separator are always present in the string, you should not have problems.

Can you show us one of the strings you find problems with?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(3,353 Views)