Re: Problem with text conversion
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.