Reputation: 625
I have a html string looks like this:
<html> <head> <title>some text</title> <link rel="stylesheet" href="http://www.xyz.com/css/main.mobile.css" /> ...
the text itself contains double quotes so how can I load into a NSString because I cannot do this;
NSString *html = @" "
put above html string in the double quote. My goal is to load the html string into UIVewView. Thanks in advance.
Upvotes: 3
Views: 1745
Reputation: 18995
Another way is to replace all the double quotes in string with single quotes.
Upvotes: 0
Reputation: 160
You could put a backslash in front of each quote
NSString *test = @"lorem\"ipsum\"do...";
or put the HTML in a separated file and load it into the NSString
// get a reference to our file
NSString *myPath = [[NSBundle mainBundle]pathForResource:@"myfile" ofType:@"html"];
// read the contents into a string
NSString *myFile = [[NSString alloc]initWithContentsOfFile:myPath encoding:NSUTF8StringEncoding error:nil];
// display our file
NSLog("Our file contains this: %@", myFile);
Upvotes: 1
Reputation: 15706
If you are using a string literal, then you just need to escape the double-quotes with backslashes, like this:
NSString *html = @"<html> <head> <title>some text</title> <link rel=\"stylesheet\" ...";
Upvotes: 2
Reputation: 2741
htmlStr = [htmlStr stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
THen load into webwiew
[self.webView loadHTMLString:htmlStr baseURL:nil];
Upvotes: 0