• 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: Problem with text conversion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with text conversion


  • Subject: Re: Problem with text conversion
  • From: j o a r <email@hidden>
  • Date: Mon, 29 Sep 2003 07:33:26 +0200

Does the string look all right when printed using NSLog? If not you've probably got a problem with the string encoding, something that should be automatic when using initWithContentsOfURL IMO - file a bug!

I've tried a couple of approaches to solve a similar problem recently, namely how to choose a proper encoding for downloaded HTML data. The solutions I've tried includes: NSURLResponse textEncodingName, Carbon TECSnifferObjects and custom HTML header meta tag parsing. I finally found that the recently released WebCore framework probably is the best way to get hold of this information - why not let Apple and kHTML to the job for you? ;)

You need to download WebCore from Apple's developer site and build it with your application (and you currently need to build it using GCC 3.1 and not 3.3), but once done it's as easy as this:

#import <WebCore/WebCoreEncodings.h>

NSData *htmlData = [NSData dataWithContentsOfURL: myURL];
NSString *htmlString = [WebCoreEncodings decodeData: htmlData];

To make this example easier to read I use "dataWithContentsOfURL:", but I would really never use anything but a non-synchronous download method - for example using NSURLConnection (new with WebKit).

j o a r

On 2003-09-28, at 23.51, bipro1.25 wrote:

I got a problem when reading a web page. I put the page in an NSString,
everything goes well...
But then, when I write the result in a menu, the `, i, h, and others
accentuated chars became strange ( I get those caracters instead : 3]2 3H2).

Can one oof you please help me ( here the concerned part of my code )

NSURL *plouf = [[NSURL alloc]
initWithString:@"http://www.mac4ever.com/xml/actu.html";];
NSString *datas = [[NSString alloc] initWithContentsOfURL:plouf];
NSLog(@"%@",datas);

[...]
And then : [[mac4EverMenu addItemWithTitle: title action:
@selector(goToNews:) keyEquivalent: @""] setTarget:self];

( title is a substring of datas )
_______________________________________________
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.

References: 
 >Problem with text conversion (From: "bipro1.25" <email@hidden>)

  • Prev by Date: Re: Best way to implement NSProgressIndicator
  • Next by Date: Re: Best way to implement NSProgressIndicator
  • Previous by thread: Problem with text conversion
  • Next by thread: Best way to implement NSProgressIndicator
  • Index(es):
    • Date
    • Thread