• 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: stringWithContentsOfFile:usedEncoding returns no err and no encoding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stringWithContentsOfFile:usedEncoding returns no err and no encoding


  • Subject: Re: stringWithContentsOfFile:usedEncoding returns no err and no encoding
  • From: Greg Parker <email@hidden>
  • Date: Fri, 30 May 2014 22:08:43 -0700

On May 30, 2014, at 9:59 PM, Trygve Inda <email@hidden> wrote:
> I have a database file exported as text from FileMaker which has several
> high-ASCII French characters.
>
> NSError* error = nil;
> NSStringEncoding* enc = nil;
>
> NSString* contents = [NSString stringWithContentsOfFile:path
> usedEncoding:enc error:&error];
>
>
> This works but enc and error are both nil after the method returns, even
> though contents is correct.
>
> NSString* contents = [NSString stringWithContentsOfFile:path encoding:
> NSASCIIStringEncoding error:&error];
>
> This one returns no error but the high ASCII French acented chars are messed
> up.
>
> NSString* contents = [NSString stringWithContentsOfFile:path encoding:
> NSUTF8StringEncoding error:&error];
>
> This returns error 261 (file can't be interpreted).
>
> So why in the first example is it working (no error) but also not returning
> any encoding value?

You're calling -stringWithContentsOfFile:usedEncoding:error: incorrectly. Try this:

NSError *error = nil;
NSStringEncoding enc;
NSString* contents = [NSString stringWithContentsOfFile:path
usedEncoding:&enc error:&error];

Note that NSString may not be able to guess your file encoding correctly. If you can discover which encoding FileMaker actually uses you'll be better off. (MacRoman is a good guess.)


--
Greg Parker     email@hidden     Runtime Wrangler



_______________________________________________

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


References: 
 >stringWithContentsOfFile:usedEncoding returns no err and no encoding (From: Trygve Inda <email@hidden>)

  • Prev by Date: stringWithContentsOfFile:usedEncoding returns no err and no encoding
  • Next by Date: Fwd: mavericks style tabs
  • Previous by thread: stringWithContentsOfFile:usedEncoding returns no err and no encoding
  • Next by thread: universal app - with iPad disabled
  • Index(es):
    • Date
    • Thread