1

I have some French text in my application. I need to write that text to the document directory as an HTML file. When I write the file using NSFileHandler, the strings with special characters are not saved correctly.

Here is my code :

NSString * udString =@"DÉTAIL DES ITEMS";
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:htmFileName];
if (fileHandle){
    [fileHandle seekToEndOfFile];
    [fileHandle writeData:convertedlogoimageData];
    [fileHandle seekToEndOfFile];
    [fileHandle writeData:[udString dataUsingEncoding:NSUnicodeStringEncoding]];
    [fileHandle seekToEndOfFile];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • `The strings with special characters are not saved correctly` How do know that? Where do you read it then? Do you use on reading `NSUnicodeStringEncoding` too and not UTF8? – Larme Dec 15 '17 at 14:21
  • The characters are saved exactly as you told them to be saved - using the Unicode encoding. That is neither correct nor incorrect. It all depends on how you need to read the file. Please update your question (do not post comments) with details about how you read the file. You are either reading the file incorrectly or your should specify a different encoding when writing the file (such at UTF-8). – rmaddy Dec 15 '17 at 15:08

0 Answers0