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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
NSString from bool array BlobbleGame iPhone/iPad Programming 5 Jun 25, 2011 04:29 PM
Trying to find line of code causing error please help! mandude iPhone/iPad Programming 5 Jan 12, 2011 03:11 PM
Vertical lines covering half of my display bobbytomorow MacBook 13 Jan 2, 2011 09:35 PM
Macbook Air 13" 2010 thin white lines across bottom half of screen ishopukisfake MacBook Air 6 Dec 16, 2010 05:11 PM
time machine backup issue (command line problem) z1snow Mac Peripherals 0 Nov 7, 2010 12:52 AM


All times are GMT -5. The time now is 09:02 AM.

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

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