• 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: Equivalent to the fscanf() C function in Cocoa?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Equivalent to the fscanf() C function in Cocoa?


  • Subject: Re: Equivalent to the fscanf() C function in Cocoa?
  • From: Mark de Jong <email@hidden>
  • Date: Thu, 22 Aug 2002 09:31:40 -0700

Alternatively, you can live dangerously and apply scanf() to the
"cString" message in "NSString".

As in:

void scanfTest( void )
{
NSString *s = @"5 10 15 20";
int v1 = 0,
v2 = 0,
v3 = 0,
v4 = 0;
int result = 0;


result = sscanf( [s cString], "%d %d %d %d", &v1, &v2, &v3, &v4 );

NSLog( @"s:%@, v1:%d, v2:%d, v3:%d, v4:%d",
s, v1, v2, v3, v4 );
}

HTH,

-- Mark

On Thursday, August 22, 2002, at 08:34 AM, <email@hidden>
wrote:

> Two easy ways come to mind:
>
> Using the NSScanner Foundation class is one way. It is fairly
> flexible, so
> check the docs to see what it can do.
>
> Also, check out the docs for NSString. The componentsSeparatedByString
> method is another way to do what you are asking.
>
>
> From: Arthur VIGAN <email@hidden>
> Date: Thu, 22 Aug 2002 15:26:36 +0200
> To: Cocoa Dev <email@hidden>
> Subject: Equivalent to the fscanf() C function in Cocoa?
>
>
> Hi,
>
> Is there an equivalent to the C function fscanf() in the Cocoa
> framework for
> an NSString?
> The "problem" is that my application generates strings containing int
> values
> separated by a space (for instance: "150 221 14 487 174") that I would
> like
> to put in an array.
>
> Thanks in advance.
>
> Arthur
> _______________________________________________
> 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.
> _______________________________________________
> 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.
_______________________________________________
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.

  • Prev by Date: Deallocating Distributed Objects
  • Next by Date: Re: Bundle loading
  • Previous by thread: Re: Equivalent to the fscanf() C function in Cocoa?
  • Next by thread: Re: Equivalent to the fscanf() C function in Cocoa?
  • Index(es):
    • Date
    • Thread