1

I'm trying to edit a piece of html from an rss in a UIWebView. Right now, I'm trying to change the font of the html. I do so by putting a piece of html before and after the HTML(the html is just

loads of text

). But when I try to do this, Xcode detects syntax-errors in my code even though it's within a string. Is there any way to make xcode believe that this is an actual string and not code? And why does this happen?

This is the code(written in Swift 2.0):

    let startHTML = "<font face="verdana" color="green">"

    let endHTML = "</font>"

    let myHTMLString:String = startHTML + entryDescription + endHTML

    web.loadHTMLString(myHTMLString, baseURL: nil)

And this is how the Syntax-error shows up(CLICK ME)

4
  • You need to escape the quotes, else the first quote that comes up ends your string, and the rest of the line is invalid code. Commented Jul 16, 2015 at 16:22
  • @Måns Larsson: If you got any answer helpful for you then please mark it as accepted don't give just comment it's working, because when ever another programmer stuck with same problem your accepted answer will help to them. I hope you will understand what I am trying to say. :) Commented Jul 16, 2015 at 16:49
  • @PravinTate Oh, sorry, you guys were so good at answering that I wasn't able to accept the answer because the 5-minutes-until-accepting limit was still active. I was planning on coming back after a couple of minutes but never did it, I was to busy programming! I've now accepted one of the answers! Commented Jul 16, 2015 at 22:04
  • OK other programmers find time for help in your problem so always give vote up of right answer so they will get motivation for answering other answer. Commented Jul 17, 2015 at 0:38

3 Answers 3

3

You must escape the double quotes within a string with a leading backslash.

let startHTML = "<font face=\"verdana\" color=\"green\">"

For further information see the Swift docs on string literals.

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

Comments

1

Your double quotes are breaking the string up. You need to add a backslash which will prevent the string from being split up.

let startHTML = "<font face=\"verdana\" color=\"green\">"

Comments

1
let startHTML = "<font face=\"verdana\" color=\"green\">"

    let endHTML = "</font>"

double quotes show as string so in your string your set face=" so it will think that string is end there. so in string while you add any double quote add \ before that.

1 Comment

then can you please accept it or vote up answer so for another programmers it will help

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.