too may "s in a String

Hi ,


I have a string value (actually html code) , and it dose have too many " <- this quotation.


So, if I write that string code like a way , var a : String = "sdfsdfdsfdsfsdfdsf", it dose not work.


(because it looks like "sadas"dsfs"vdssd"vsdvdsv"sdsdfg"" like this.


It is hard to input someting like \" manually , because a value is dynamic.


Any way to do this in swift ?

Accepted Reply

Any way to do this in swift ?

Not directly. Support for more advanced forms of quoting is something that regularly crops up on swift-evolution. There’s a general consensus that it’s important but there isn’t yet a plan in place to address it.

I generally deal with this issue in one of two ways:

  • For small chunks of text, I use search and replace to add the quotes.

  • For large chunks of text, I put the text in a separate

    .html
    document in my bundle and then load that programmatically.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

Any way to do this in swift ?

Not directly. Support for more advanced forms of quoting is something that regularly crops up on swift-evolution. There’s a general consensus that it’s important but there isn’t yet a plan in place to address it.

I generally deal with this issue in one of two ways:

  • For small chunks of text, I use search and replace to add the quotes.

  • For large chunks of text, I put the text in a separate

    .html
    document in my bundle and then load that programmatically.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"