Reputation: 153
I have a submit form where there are multiple textfields. Whenever user enters text like "Hi, my name is "xyz"", the service does not accept this JSON due to double quotes in my string. Please suggest ways to escape this character. I have tried using encode and decode JSON, replaceOccurrencesOf methods, but none work.
replaceOccurrencesOf()
Upvotes: 4
Views: 3825
Reputation: 71
The below code snippet with replace "(double quote) in a string by \". This will help to replace "(double quote) by any string or character in a given string.
Swift 5 or above
let replacedString = stringToBeModified.replacingOccurrences(of: "\"", with: #"\""#)
Upvotes: 5
Reputation: 468
Instead of putting the name (i.e., "XYZ" if you getting xyz from textfield ) why not to place (textField.text!) it will not put extra " "
Upvotes: 0