Re: A question about text
Re: A question about text
- Subject: Re: A question about text
- From: "M. Uli Kusterer" <email@hidden>
- Date: Wed, 14 Apr 2004 17:52:12 +0200
At 20:04 Uhr -0400 12.04.2004, Tom wrote:
I'm sorry, I just don't get how to use NSScanner. I'm really new,
self taught, and I have no one else to help me. If it's possible can
someone just show me how to use NSScanner. I tried Apple's
documentation but it's no use.
NSScanner is pretty simple to use, actually. Basically, you need an
NSString with the data to scan. Then create an NSScanner object with
that string (NSScanner's initWithString:).
An NSScanner has a "current reading offset" not unlike the
read/write mark of a file, which you can query with scanLocation and
change using setScanLocation: and then you can use one of the scanXXX
methods on it, which work relative to that offset, and advance the
scanLocation.
The simple methods, like scanInt: simply skip all whitespace (or
whatever charactersToBeSkipped you specify instead) until they hit
something, and then set the variable passed as their parameter to the
value they scanned, or if they couldn't make sense of it, they just
return NO.
scanString:intoString: works similarly, just that it only reads a
string if it matches what you've passed in.
scanUpToString:intoString: works differently, and just eats whatever
characters it finds until it encounters the specified string.
It's all fairly simple, but quite powerful if you combine it, and
more specialized than regular expressions, and thus has potential to
be faster. Read the NSScanner docs on Apple's web site, or your local
copy in the xCode documentation viewer for all the gory details.
At first glance, NSScanner doesn't look like much, but as most of
Cocoa, it does exactly what is needed to get the tedious parts out of
the way, while not doing so much as to be in the way.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.