• 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
How to grab everything in a string before a space?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to grab everything in a string before a space?


  • Subject: How to grab everything in a string before a space?
  • From: Keith Pritchard <email@hidden>
  • Date: Mon, 2 Sep 2002 22:25:36 +0100

Hi all,

So tempting to use plain C here ;-) but I'm trying to learn how to do
it properly soo.....

Have an NSString which looks like "Item1 abcde 12345 y" and all I
need is to get the word before the first space, so, item1 in the
example above.

Been trying the below but getting a crash -> sigsegv or
incompatible pointer type depending how I play with the definitions.....

Whats the easiest way to grab that first word out of the string? Thanks!

NSString *str1;
NSScanner *myScanner=[NSScanner scannerWithString:myString];
[myScanner scanUpToString:@" " intoString:str1];

Having read the docs a little more, I'm getting the feeling that I may
need to tell NSScanner not to ignore spaces (does it really default to
ignoring spaces/newlines! eek?!)

Any hints appreciated,
Cheers,
Keith
_______________________________________________
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.

  • Follow-Ups:
    • Re: How to grab everything in a string before a space?
      • From: Ondra Cada <email@hidden>
  • Prev by Date: cString deprecated!
  • Next by Date: Re: cString deprecated!
  • Previous by thread: Re: cString deprecated!
  • Next by thread: Re: How to grab everything in a string before a space?
  • Index(es):
    • Date
    • Thread