Re: Get the number of lines of text in an NSTextView?
Re: Get the number of lines of text in an NSTextView?
- Subject: Re: Get the number of lines of text in an NSTextView?
- From: Todd Ditchendorf <email@hidden>
- Date: Tue, 24 Jan 2006 17:34:15 -0600
Thanks Doug. Um, I'm only wanting to count line breaks, as I have
configured my NSTextView and its NSScrollView to NOT wrap text.
So line breaks should do it.
I've just found the following code snippet in Apple's docs... it does
the trick. I was thinking that some internal structure might track
the number of lines, but between what you're saying and the fact that
this mini-algorithm is in the apple docs, that there's no such
animal. Can anyone confirm/deny?
NSString *s = [aTextView string];
unsigned numberOfLines, index, stringLength = [s length];
for (index = 0, numberOfLines = 0; index < stringLength;
numberOfLines++) {
index = NSMaxRange([s lineRangeForRange:NSMakeRange(index, 0)]);
}
return numberOfLines;
Todd Ditchendorf
http://ditchnet.org
http://scan.dalo.us (Cocoa Developer Tools)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden