I'm looking for a way to either iterate over each line in an NSString or to to count the number of lines in an NSString so that I can iterate over them . If anyone could point me in the right direction it would be much appreciated!

Also, is there a way to strip unwanted characters from the start/end of a line: like chomp in perl or strip() in Python.

Thanks Robbie, the stringByTrimmingCharactersInSet: method was just what I was looking for .

I'm not so sure about the line separation because the approach doesn't seem unicode compatible (I could be wrong).

Code:

From the docs on "getLineStart:end:contentsEnd:forRange:"
A line is delimited by any of these characters, the longest possible sequence being preferred to any shorter:
U+000D (\r or CR)
U+2028 (Unicode line separator)
U+000A (\n or LF)
U+2029 (Unicode paragraph separator)
\r\n, in that order (also known as CRLF)

Maybe someone could answer this: in a unicode string, is the line terminator still "\n" or some other character? The string I'm working with is from an NSTextView if that helps.