Re: Converting an HTML source string to a readable string
Re: Converting an HTML source string to a readable string
- Subject: Re: Converting an HTML source string to a readable string
- From: j o a r <email@hidden>
- Date: Fri, 12 May 2006 08:46:21 +0200
On 12 maj 2006, at 08.28, Eric Morand wrote:
I've tried to convert the string with various encoding, using :
MyString = [NSString stringWithContentsOfURL:[NSURL
URLWithString:@"http://www.gamekult.com/communaute/chat/"]];
NSData * data = [MyString dataUsingEncoding:NSUnicodeStringEncoding
allowLossyConversion:YES];
MyString = [[NSString alloc] initWithData:data
encoding:NSUnicodeStringEncoding];
But it doesn't change anything.
You're doing unnecessary, and probably incorrect, conversions. Go to
NSData first, and then to NSString using an explicit encoding:
NSData *data = [NSData dataWithContentsOfURL: theURL];
NSString *string = [[[NSString alloc] initWithData: data encoding:
NSISOLatin1StringEncoding] autorelease];
Note however, that this will not solve your problem unless you happen
to find out the correct encoding to use! Don't use
NSUnicodeStringEncoding (or any other encoding) unless you're _sure_
it's the right one!
Also note that regular string encodings will not (AFAIK) handle HTML
character encodings for you. To do that, you might be able to use the
functionality provided by NSAttributedString (in the AppKit
additions). Init an attributed string with your HTML data, and then
grab a plain NSString from this attributed string.
Or perhaps there's functionality in WebKit to do this?
j o a r
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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