• 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: Saving UTF-8 as File
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving UTF-8 as File


  • Subject: Re: Saving UTF-8 as File
  • From: Jim Hamilton <email@hidden>
  • Date: Tue, 19 Apr 2005 14:26:31 -0400

[oops, forgot to copy to the list]

On Apr 19, 2005, at 1:53 PM, August Trometer wrote:

I have a situation where I need to create some HTML on the fly and save it to a file, then turn around and have WebKit read the file using a file:// URL. (Why? NDA until the 29th.)

If I give WebKit the straight string, it handles any UTF-8 characters just fine.

However, when I save to a file (using NSString writeToFile:atomically), it doesn't save as UTF-8 and when the file is read I get all kinds of bogus characters.

Ahem:

writeToFile:atomically:

<x-tad-bigger>- (BOOL)writeToFile:(NSString *)</x-tad-bigger><x-tad-bigger>path</x-tad-bigger><x-tad-bigger> atomically:(BOOL)</x-tad-bigger><x-tad-bigger>flag
</x-tad-bigger>
Writes the contents of the receiver to the file specified by path. path is written in the default C-string encoding if possible (that is, if no information would be lost), in the Unicode encoding otherwise.

I don't know about you, but I kind of want to know exactly what's getting written before I start. In any case, neither of those choices is UTF-8.

Try writing directly what's pointed by the pointer returned by - UTF8String, or putting that into an NSData and using its writeToFile:atomically: method.

Also:

Can someone point me in the right direction to be able to save the HTML string as a UTF-8 encoded file?


1) Do you start the file with a BOM? (Check unicode.org to be sure, but I think it's 0xEF 0xBB 0xBF.)

2) Does your HTML have an encoding tag? ("charset=utf-8" in a meta tag)

HTH,
Jim H
--
Jim Hamilton
Senior Software Engineer
Fine Point Technologies, Inc.
139 Centre Street, 6th floor
New York, NY 10013-4408
phone: +1.212.962.7410 ext. 316
fax: +1.212.962.7404
email: email@hidden
web: http://www.finepoint.com

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Saving UTF-8 as File
      • From: John Stiles <email@hidden>
References: 
 >Saving UTF-8 as File (From: August Trometer <email@hidden>)

  • Prev by Date: Re: Saving UTF-8 as File
  • Next by Date: Re: Saving UTF-8 as File
  • Previous by thread: Re: Saving UTF-8 as File
  • Next by thread: Re: Saving UTF-8 as File
  • Index(es):
    • Date
    • Thread