I want to concatenate to a string another which contains the " ' " characters the string look as wanted But when I create an Object with this string, I'm getting a "\" inside it:
I check in https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html#//apple_ref/doc/uid/TP40014097-CH7-ID285 how to deal with special character
EDIT: I made a mistake in understanding the source of my problem... When I try to build a URL with URLQueryItem , there Im getting
print(EventToUrl.name) // print John's Event
let name = URLQueryItem(name: "name", value: EventToUrl.name)
print(name.description) //print name=John's Event
print(name.value) // print Optional("John\'s Event")
deepLink.queryItems = [name]
print(deepLink.url) //print Optional(https://www.example.com/?id%3D-KZXZG2bcuKHNdYNcGTF%26name%3DJohn's%2520Event%26....)
And when i try to send this deep link Im getting an error because of the " ' " characters
I also try Eric Aya's answer here : How to use special character in NSURL? but that not working for me:
print(EventToUrl.name) //print "John's Event"
let name = URLQueryItem(name: "name", value: EventToUrl.name.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed))
print(name.description) //Print name=John's%20Event
print(name.value) //Print Optional("John\'s%20Event")
print(deepLink.url) //print
Optional(https://www.example.com/?id%3D-KZXWVbBolmso5DT4p2I%26name%3John's%252520Event%26.......)
Self contained code :
var urlTestComponents = URLComponents()
urlTestComponents.scheme = "https"
urlTestComponents.host = "www.example.com"
urlTestComponents.path = "/"
let nameTest = URLQueryItem(name: "name", value: "John's Event")
urlTestComponents.queryItems = [name]
print(urlTestComponents.url)
The last line prints "https://www.example.com/?name=jeremie's%20Event" and If I try to send that (with whatsApp) the url is cut at the middle because of the " ' "