john doe john doe - 1 year ago 91
Objective-C Question

Adding back slash for quotes in Swift

I have the following code in Objective-C:

NSString *someString = @"Hello World";

I need a Swift Code with the following output:
\"Hello World\"

Including the double checkmarks and the backslash.

Answer Source

According to your comment, you'll need this:

var mySuperFancyDynamicString: String = "whaaaazzuppp"

let someString: String = "\\\"\(mySuperFancyDynamicString)\\\""

print is \"whaaaazzuppp\" (well... was Hello World, before the edit)

enter image description here

Or to your "text box" Comment:

var mySuperFancyDynamicString: String = textBox.text
let someString: String = "\\\"\(mySuperFancyDynamicString)\\\""

Print will be : \"textBoxContent\"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download