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: Conor Dearden <email@hidden>
- Date: Fri, 12 May 2006 11:09:27 +0200
Here you go, a function from DVDpedia flipped to be used backwards (I use it
to go from UTF-8 to HTML encoding):
Just add the following line after you get your string:
[self convertHTMLEncoding:MyString];
Add this function to your class:
- (NSString *)convertHTMLEncoding:(NSString *)aString {
NSMutableString *tempMutableString = [NSMutableString
stringWithCapacity:150];
[tempMutableString setString:aString];
while (YES) {
int tempInt = 0;
NSScanner *searchScanner = [NSScanner
scannerWithString:tempMutableString];
[searchScanner scanUpToString:@"&#" intoString:nil];
if ([searchScanner isAtEnd])
break;
[searchScanner setScanLocation:[searchScanner scanLocation] +2];
[searchScanner scanInt:&tempInt];
if (tempInt) {
if ([tempMutableString replaceOccurrencesOfString:[NSString
stringWithFormat:@"&#%d;", tempInt] withString:[NSString
stringWithFormat:@"%C", tempInt] options:NSLiteralSearch
range:NSMakeRange(0, [tempMutableString length])] == 0)
[tempMutableString
deleteCharactersInRange:NSMakeRange([searchScanner scanLocation] -2 ,2)];
}
else
[tempMutableString
deleteCharactersInRange:NSMakeRange([searchScanner scanLocation] -2 ,2)];
}
return tempMutableString;
}
Regards,
Conor
http://www.bruji.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