• 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
wordRangeForRange implememtation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

wordRangeForRange implememtation


  • Subject: wordRangeForRange implememtation
  • From: Lincoln Green <email@hidden>
  • Date: Sat, 10 May 2008 15:26:26 -0500

- (NSRange)wordRangeForRange:(NSRange)range{
NSString *string = [NSString stringWithString:[[self string] substringWithRange:range]];
if([string hasPrefix:@" "]){
[string stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""];
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)] == @" "){
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/

_______________________________________________

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


  • Follow-Ups:
    • Re: wordRangeForRange implememtation
      • From: Ali Ozer <email@hidden>
    • Re: wordRangeForRange implememtation
      • From: Nathan Kinsinger <email@hidden>
  • Prev by Date: Re: NSStream blocking behavior?
  • Next by Date: Re: Problem getting subclass of NSTextContainer working
  • Previous by thread: Re: iChat theater
  • Next by thread: Re: wordRangeForRange implememtation
  • Index(es):
    • Date
    • Thread