NSString newbie question
NSString newbie question
- Subject: NSString newbie question
- From: John Fowler <email@hidden>
- Date: Wed, 20 Aug 2003 07:44:25 -0500
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.