• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSScanner searches from start
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSScanner searches from start


  • Subject: Re: NSScanner searches from start
  • From: Ivan Myrvold <email@hidden>
  • Date: Mon, 25 Jun 2001 09:41:40 +0400

But if I put the statement:

NSString *animal = @"Dog";

the scanUpToString:intoString also returns YES, even if the string "Dog" is not a part of the string. Is that a bug, then?

Ivan

On Sunday, June 24, 2001, at 03:51 PM, John C. Randolph wrote:

On Sunday, June 24, 2001, at 04:39 AM, Ivan Myrvold wrote:

I have just started to use NSScanner, and it obviously only finds patterns from start. Here is an example:

NSScanner *myScanner;
NSString *animal = @"Cow";

myScanner = [NSScanner scannerWithString:@"ChickenAndTheCow"];
if([myScanner scanString:animal intoString:NULL]) {
NSLog(@"Animal");
} else {
NSLog(@"Not an animal");
}


This gives the result "Not an animal", but if I initialize NSString *animal with "Chicken", this results in "Animal" in the log.

How can I get NSScanner to also recognize "Cow" in the string?

What you need in this case is -scanUpToString:, not -scanString:.

I also have a problem to understand what the parameter intoString: does.

The parameter after intoString: is where the method will put whatever characters it scanned.

For example:

NSString *firstNameAndInitial
NSScanner *nameScanner = [NSScanner scannerWithString:@"John C. Randolph"];
[nameScanner scanUpToString:@"Randolph" intoString:firstNameAndInitial];

at this point, firstNameAndInitial points to a string equal to @"John C. "

-jcr


"Scientology is both immoral and socially obnoxious... it is
corrupt, sinister and dangerous." - Mr. Justice Latey, London 1984
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


  • Follow-Ups:
    • Re: NSScanner searches from start
      • From: "John C. Randolph" <email@hidden>
References: 
 >Re: NSScanner searches from start (From: "John C. Randolph" <email@hidden>)

  • Prev by Date: objective-c question/clarification
  • Next by Date: Re: objective-c question/clarification
  • Previous by thread: Re: NSScanner searches from start
  • Next by thread: Re: NSScanner searches from start
  • Index(es):
    • Date
    • Thread