• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSString newbie question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSString newbie question
      • From: Glen Simmons <email@hidden>
References: 
 >NSString newbie question (From: John Fowler <email@hidden>)

  • Prev by Date: Re: Drag and drop promised files to Finder
  • Next by Date: Re: Maintaining Z-Order while hiding NSViews
  • Previous by thread: Re: NSString newbie question
  • Next by thread: Re: NSString newbie question
  • Index(es):
    • Date
    • Thread