Re: NSString newbie question
Re: NSString newbie question
- Subject: Re: NSString newbie question
- From: Robert Cerny <email@hidden>
- Date: Wed, 20 Aug 2003 16:07:29 +0200
Hi,
the problem is that not only \n can be on the end of the row, but also
\r or \n\r. These line endings indicate from which platform the
original file is. I can recommend you to use NSScanner to find your
row, in combination with NSCharacterSet
HTH
Robert
On Wednesday, August 20, 2003, at 02:44 PM, John Fowler wrote:
I am learning about cocoa and objective C. I am creating a project to
parse a block of text into lines.
My question about the following is: Why does the separation string
"\n" not work? What general character or other workaround can I use to
divide text into lines? A snippet of my test block is here:
Spot Check Pulse Oximetr
ABORH ROUT
XM IM SPIN
Bedside Pulse Oximeter
The code about which I have a question is here:
NSString * excl =[NSString stringWithContentsOfFile:filename];
NSArray * linesarray = [excl componentsSeparatedByString:@"\n"];
int count=[linesarray count];
printf("linesarray count: %d\n",count);
int j;
for (j=0;j<count;j++){
printf("%d: %s\n",j,[[linesarray objectAtIndex:j] UTF8String]);
}
The code yields an array intended to be an array of the lines from the
text. However for the test block the code only gets one array element,
apparently not seeing any "\n" in the test block. Relevant output
looks like this:
linesarray count: 1
0: Spot Check Pulse Oximetr
ABORH ROUT
XM IM SPIN
Bedside Pulse Oximeter
If I use this text as a test block:
a
b
c
d
e
I get this output:
linesarray count: 5
0: a
1: b
2: c
3: d
4: e
which is more like what I would have predicted.
There must be some other hidden character separating the lines in the
first test block. What generalizable character or character set can I
use to parse lines from text? Is there something about NSString that I
don't understand? Suggestions might put me on the right path. Thanks
in advance.
John Fowler
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.