0

I am getting HTML from Server as NSString. I need to apply CSS on that HTML. What I tried

NSString *htmlString = @"This is an example of a lorem ipsum dolor longer question that has about twenty-two words in it, est veniam dolorum?";


NSString *htmlStringQuestion = [NSString stringWithFormat:@"<style type='text/css'>* {padding:0px; margin:0px;} div.ContentWrapper {width:100%; height:100%; text-align:center; display:table;}div.ContentArea {display:table-cell; vertical-align:middle; padding:0 5%; background:#ff0000;color: #FF0; font-size:30; font-family: Baskerville;}</style><div class='ContentWrapper'><div class='ContentArea'><p>%@</p></div></div>", htmlString];

Now its giving warning.

enter image description here

Thanks.

8
  • You need to escape all special characters from htmlStringQuestion (special characters being: / % ; etc...) Commented Nov 27, 2015 at 5:15
  • So, If I remove these characters, It will loss essence of being CSS or HTML. As we are removing Tags Commented Nov 27, 2015 at 5:17
  • Escaping the characters is not removing them. You escape them by adding a `\` before them. Have a look at this: stackoverflow.com/questions/5588495/… and stackoverflow.com/questions/15026942/… Commented Nov 27, 2015 at 5:17
  • This is local String @Bassem, So I need to apply CSS, if I remove this %, it will not be functional as CSS. Commented Nov 27, 2015 at 5:26
  • 1
    @Bassem No, you escape each % by adding a 2nd %. You do not add a backslash. Commented Nov 27, 2015 at 5:52

1 Answer 1

2

You need to properly escape each % literal in the format string by making it %%. If you had any double-quotes in the format string, those would need to be escaped by prepending a backslash like \".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.