In Xcode with swift, how can I save text with quotation marks in it from a UItextfield into a string variable. I know how to use escape in a string "\"", but can't find a way to replace it from user input text field?
I am experimenting with encryption algorithms. I want my function to be able to take any type of user input, but keep hitting an error when my program tries to deal with quotation marks from the user input field at run time. I was hoping that a search replace type function might exist that would take user input and replace " with /". The documentation talks about escape sequences in relation to a string in the program that exists prior to running the program not for text that doesn't exist until the user types it in and hits the encrypt button.
I tried the suggestion below and:
var str = "I said \"Hello Everybody\"..."
var newstr = str.stringByReplacingOccurrencesOfString("\"", withString: "")
This would work, but the text coming in from the User interface is unescaped like this...
I said "Hello Everybody"
When I try the code above on the text from the text field, it will not find and replace the quote.
It lacks the escape characters, and even if I were to put them in the UIText as a user, I get an error when trying to replace the quotes. It works for a string, but not for user input...I can find and replace any other type of character from the UITextField, but I keep hitting a snag when it comes to these quotes.
I would really like to find a way of replacing the unescaped quote with an escaped one as below, but can't because the """ is in itself unescaped.
var newstr = str.stringByReplacingOccurrencesOfString(""", withString: "/"")