Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 14, 2005, 11:46 AM   #1
netytan
macrumors 6502
 
Join Date: May 2004
NSString & lines.

Hi again guys,

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 in advance,

Mark.
__________________
12" G4 IBook (1GHz) named Darwin: 60GB HardDrive, BlueTooth, Airport Extreme coming soon?
netytan is offline   0 Reply With Quote
Old Jan 14, 2005, 12:02 PM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Take a look at the NSString documentation on XCode. The - (NSArray *)componentsSeparatedByStringNSString *)separator looks promising (@"\n" would be the separator)

- (NSString *)stringByTrimmingCharactersInSetNSCharacterSet *)set can be used like chomp.
robbieduncan is offline   0 Reply With Quote
Old Jan 14, 2005, 12:35 PM   #3
netytan
Thread Starter
macrumors 6502
 
Join Date: May 2004
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.

Thanks again ,

Mark.
__________________
12" G4 IBook (1GHz) named Darwin: 60GB HardDrive, BlueTooth, Airport Extreme coming soon?
netytan is offline   0 Reply With Quote
Old Jan 14, 2005, 12:50 PM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Seems to be a fair point. Create some sort of recursive method to loop over separating by each possible line end character in turn?
robbieduncan is offline   0 Reply With Quote
Old Jan 14, 2005, 02:40 PM   #5
northen
macrumors member
 
Join Date: Jan 2005
Location: Aalborg, Denmark
I wrote a C library to do something like that, available at

http://savannah.nongnu.org/projects/velocity/

It's a bit stubby right now, but it will eventually have a VCount method. I haven't worked on it for a bit, though :P
__________________
PM G5| Dual 2GHz, 4 GB RAM, 76 GB WD Raptor, 250 GB Maxtor, Radeon 9600 XT
iBook G4 | 1.0 GHz, 12", 768 MB RAM
northen is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
AT&T Mobile Share 3 lines with 10GB gbuc95 iPhone 0 Sep 14, 2013 08:38 AM
Need advice on my 2 lines with AT&T sulpfiction iPhone 9 Jul 7, 2013 01:32 PM
NSString format & xtra characters Dreamspinner Mac Programming 11 Dec 24, 2012 12:41 PM
how to remove & from NSString Narendar Singh iPhone/iPad Programming 7 Dec 12, 2012 08:34 AM
AT&T account under my name, sending wife into the lines.. richpuer iPhone 3 Sep 20, 2012 07:30 PM

Forum Jump

All times are GMT -5. The time now is 02:56 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC