Re: NSString newbie question
Re: NSString newbie question
- Subject: Re: NSString newbie question
- From: Glen Simmons <email@hidden>
- Date: Wed, 20 Aug 2003 10:13:44 -0500
You forgot the Unicode line & paragraph endings. The
getLineStart:end:contentsEnd:forRange: method deals with all of these
properly. I've used it for this type of thing and it works well.
HTH,
Glen
On Wednesday, August 20, 2003, at 09:07 AM, Robert Cerny wrote:
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.
_______________________________________________
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.