Re: Grabbing substring from a NSPipe
Re: Grabbing substring from a NSPipe
- Subject: Re: Grabbing substring from a NSPipe
- From: John Pannell <email@hidden>
- Date: Wed, 21 Aug 2002 15:18:21 -0600
Hi there-
I did something similar, and used NSScanner to parse through the pipe
output. I think that is what you want to look at - the docs are pretty
good.
John P.
On Wednesday, August 21, 2002, at 02:50 PM, email@hidden wrote:
hi,
I'm trying to grab a substring from a Command line, I've got the NSPipe
working thanks to the Guys/Gals at CocoaDevCentral :)
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?
I tried reading the NSString and the only close I could find is a
appendString but it only tells me how to add the substring to temp. Not
how to copy the subString from the NSString string value.
Can anyone give me a hint on how to copy the text out of the string???
Thanks,
Erick
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.