views:

809

answers:

3

I have a piece of NSString that will read "Test & Test" or with "

Is there any way without searching and replacing to make that display as "&" or """ ??

A: 

Hi,

The html string you read is bad formated.

Try to read as UTF-8 or any other formatting in order to get the correct text from the html you're reading.

Can you actually post the code where you read the NSString from the HTML content ?


Adrian

Online Timesheet Software

Adrian Pirvulescu
NSString *webpage = [NSString stringWithContentsOfURL:[NSURL URLWithString:escapedURL]];
Lee Armstrong
A: 

Hi,

Can you try this ?

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.mypage.com/content.html"]]];
[request setHTTPMethod:@"GET"];

NSHTTPURLResponse* authResponse;
NSError* authError;
NSData * authData = [NSURLConnection sendSynchronousRequest:request returningResponse:&authResponse error:&authError];      

NSString *authResponseBody = [[NSString alloc] initWithData:authData encoding:NSUTF8StringEncoding];

NSLog(@" Nice Result: %@", authResponseBody);


Adrian

Adrian Pirvulescu
Code works but still comes back as...<title>Tyres 4.3" Round</title>
Lee Armstrong
Try to open the same page with a web-browser like Firefox and the choose to see page source. If inside the page source you see the same " chars.. then the problem is the page itself. try to set the html page encoding to UTF-8 :)
Adrian Pirvulescu
Yeah the page is at fault :-( Thanks
Lee Armstrong
Logan Capaldo
A: 

CFXMLCreateStringByUnescapingEntities should do it. Thanks to the magic of toll free bridging you can just use your NSString.

Logan Capaldo