Skip navigation.
 
mlwordRangeForRange implememtation
FROM : Lincoln Green
DATE : Sat May 10 22:26:26 2008

- (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
Isildur.<email_removed>
http://www.binkworks.com/

Related mailsAuthorDate
mlwordRangeForRange implememtation Lincoln Green May 10, 22:26
mlRe: wordRangeForRange implememtation Nathan Kinsinger May 11, 02:46
mlRe: wordRangeForRange implememtation Ali Ozer May 11, 04:42
mlRe: wordRangeForRange implememtation Ali Ozer May 11, 04:45
mlRe: wordRangeForRange implememtation Jérome Laurens May 11, 23:45
mlRe: wordRangeForRange implememtation Kyle Sluder May 11, 23:50
mlRe: wordRangeForRange implememtation Adam R. Maxwell May 12, 00:39