Re: Grabbing substring from a NSPipe
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.