Re: wordRangeForRange implememtation
Re: wordRangeForRange implememtation
- Subject: Re: wordRangeForRange implememtation
- From: Nathan Kinsinger <email@hidden>
- Date: Sat, 10 May 2008 18:46:27 -0600
On May 10, 2008, at 2:26 PM, Lincoln Green wrote:
- (NSRange)wordRangeForRange:(NSRange)range{
NSString *string = [NSString stringWithString:[[self string]
substringWithRange:range]];
if([string hasPrefix:@" "]){
[string stringByReplacingCharactersInRange:NSMakeRange(0, 1)
withString:@""];
Not sure why the above line is here, you are not using string after
this so why are you changing it?
range.location++;
}
NSString *op = [NSString stringWithString:[self string]];
int length = range.location;
int finished = 0;
while(finished != 1){ //2
if([op substringWithRange:NSMakeRange(length, 1)] == @" "){
try isEqualToString: instead of ==
finished = 1;
}else{
NSLog([op substringWithRange:NSMakeRange(length, 1)]); //1
length++;
}
}
range.length = length;
return range;
}
This code is in an NSTextView subclass.
Can anyone tell why it would not work as a wordRangeForRange:
implementation? When I run it, my loop at //2 doesn't stop until
"length" exceeds my character count, even though at //1, My console
logs a space. Any suggestions? Also, if this is not clear, post in
and I will try to explain it more clearly.
Thanks!
Lincoln Green
email@hidden
http://www.binkworks.com/
--Nathan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden