• 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
NSString ambiguities
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSString ambiguities


  • Subject: NSString ambiguities
  • From: Ariel Feinerman <email@hidden>
  • Date: Thu, 1 Jul 2010 01:02:06 +0300

Hi,

If we read whole file as a NSString, will be any conversions between \r\n,
\r, \n? Then if not, will be -componentsSeparatedByCharactersInSet:
[NSCharacterSet newlineCharacterSet] create empty strings in Win \r\n case?
So what is the best: [NSCharacterSet newlineCharacterSet] or [NSCharacterSet
characterSetWithCharactersInString: @"\n"] or simply
-componentsSeparatedByString: @"\n"?

code:

NSString *string = [[NSString alloc] initWithContentsOfFile: name encoding:
NSUTF8StringEncoding error: NULL];
NSArray *array = [string componentsSeparatedByCharactersInSet:
[NSCharacterSet newlineCharacterSet]];

[string release];
string = nil;

NSMutableString *outString = [NSString new];

for (string in array) {
     if (![string isEqualToString: @""]) {
     // ...
     [outString appendFormat: @"%@\n", string];
     }
}

[outString writeToFile: outName atomically: NO encoding:
NSUTF8StringEncoding error: NULL];

--
best regards
Ariel
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSString ambiguities
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: Re: class_respondsToSelector() in runtime.h?
  • Next by Date: Re: class_respondsToSelector() in runtime.h?
  • Previous by thread: Re: class_respondsToSelector() in runtime.h?
  • Next by thread: Re: NSString ambiguities
  • Index(es):
    • Date
    • Thread