• 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: Grabbing substring from a NSPipe
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Grabbing substring from a NSPipe


  • Subject: Re: Grabbing substring from a NSPipe
  • From: Jeff LaMarche <email@hidden>
  • Date: Wed, 21 Aug 2002 14:27:59 -0700 (PDT)

On Wednesday, Aug 21, 2002, at 01:50PM, <email@hidden> wrote:
>But now I'm trying to get a substring from the text that is returned by
>the NSPipe
>I'm trying to get the latency of a server by looking between "time="
>and " ms" to get the latency Example below. So my Question is: How do I
>grab the substring using the NSRange I made of the two whereTime/MS
>rangeOfStrings?

wouldn't substringWithRange: do it for you?

like this:

temp = [string substringWithRange: copyRange];

Or am I not understanding the question?

>
>NSData *data;
>NSRange whereTime,whereMS,copyRange;
>NSString *temp;
>
>while([data=[handle availableData] length]) { // until EOF (check
>reference)
> NSString *string=[[NSString alloc] initWithData:data
>encoding:NSASCIIStringEncoding];
> //So string contains the text returned from the command line
> temp = [[NSString alloc] init];
>
> whereTime = [string rangeOfString:@"time="
>options:NSCaseInsensitiveSearch];
> //Using ping -c 1 as command so it only returns one ping.
> whereMS = [string rangeOfString:@" ms"
>options:NSCaseInsensitiveSearch];
>
> NSLog(@"%d",whereTime);
> NSLog(@"%d",whereMS);
>
> copyRange = NSMakeRange(whereTime.location +
>whereTime.length,whereMS.location+1);
>
> //temp = [copy substring using copyRange] but how to do it???
> [string release];
> [temp release];
> }
>
>
>result of the ping example
>PING euronet.nl (194.134.0.10): 56 data bytes
>64 bytes from 194.134.0.10: icmp_seq=0 ttl=251 time=149.028 ms
>
>--- euronet.nl ping statistics ---
>1 packets transmitted, 1 packets received, 0% packet loss
>round-trip min/avg/max = 149.028/149.028/149.028 ms
>_______________________________________________
>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.

  • Follow-Ups:
    • Re: Grabbing substring from a NSPipe
      • From: email@hidden
  • Prev by Date: Re: Grabbing substring from a NSPipe
  • Next by Date: Re: NSTimer in a secondary thread?
  • Previous by thread: Re: Grabbing substring from a NSPipe
  • Next by thread: Re: Grabbing substring from a NSPipe
  • Index(es):
    • Date
    • Thread