#define INRANGE(a,b) (a.location + a.length < b) - (NSRange) rangeOfLine: (unsigned int) lineNumber { NSRange lineRange; int lineCount, myLength; myLength = [self length]; lineCount = 0; lineRange.location = 0; lineRange.length = 0; // find line lineRange = [self lineRangeForRange: lineRange]; while((lineCount < lineNumber) && INRANGE(lineRange,myLength)){ lineRange.location += lineRange.length; lineRange.length = 0; lineRange = [self lineRangeForRange: lineRange]; lineCount++; } // if still in range if(INRANGE(lineRange,myLength)){ return lineRange; } lineRange.location = NSNotFound; lineRange.length = 0; return lineRange; }As for finding the ranges of the lines intersecting a given line, run the example and select some text in the top scroll view. The ranges of the lines you are intersecting will appear in the bottom scroll view. To download the full example demonstrating these methods, download the LineRange Example.
Objective Technologies Inc.
NOTE: OTI does not warrant, guarantee, or otherwise assume any responsibility or accountability for any loss or corruption caused by any of the software or suggestions mentioned or available on this page. If something bad happens as a result of using this software, it's your own fault for using it. Please report any problems to cs@object.com