Re: Best Practice for reading a string with NSScanner
Re: Best Practice for reading a string with NSScanner
- Subject: Re: Best Practice for reading a string with NSScanner
- From: Quincey Morris <email@hidden>
- Date: Fri, 3 Apr 2009 14:43:07 -0700
On Apr 3, 2009, at 12:08, Gustavo Pizano wrote:
I have a text file, which contains bunch of lines like this ones :
(sorry about the identation)
apphelp.dll 5.1.2600.5512
Application Compatibility Client Library
appmgmts.dll 5.1.2600.5512 Software
installation Service
appmgr.dll 5.1.2600.5512 Software
Installation Snapin Extenstion
asferror.dll 11.0.5721.5145 Definice
chyb ASF
asycfilt.dll 5.1.2600.5512
ati2cqag.dll 6.14.10.233 Central
Memory Manager / Queue Server Module
ati2dvaa.dll 6.13.10.5019 ATI RAGE
128 WindowsNT Display Driver
divxwmpexttype.dll
So I was doing scanning the string (which came from the file)
reading the library name and saving the result into productName,
then the version and then the description, then Im reading an empty
string to put the scanner on the next line,
[theScanner scanUpToString:@" " intoString:&productName];
[theScanner scanString:@"" intoString:NULL];
[theScanner scanUpToString:@" " intoString:&version];
[theScanner scanString:@"" intoString:NULL];
[theScanner scanUpToString:@" " intoString:&des];
[theScanner scanString:@"" intoString:NULL];
All the above in a while loop.
BUT!, here is where it got weird for me. the file is not consistent
on each road, as you can see the line that contains the
asycfilt.dll has a version, but has no description, so when
running the loop, after it successfully scan the previous road,
start scanning this particular line, gets the library name, then the
version, and in the status will get the next library name, which its
wrong, also it will happen something similar with the last library
name, which contains no version and no description, in this case in
&version will put the next library name(which is in the next line, I
didn't put it), and the description will be the version of the last
library name.
I have tried many things, but no success, I have getting the
NScharacterset for a line break, and try to read until there, but
its always doing the same thing, i guess im not using it properly. ,
I have tried putting some conditionals to see what I have just
scanned, but as you can see all data its different from each other.
I think the next thing you should try is reading the documentation
again, in particular the part about 'scanUpToString:intoString:'
skipping newline characters by default. If you change the default,
you'll likely stop falling off the ends of the lines.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden