You need to use
[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
to get the desired result. string
is the object containing your original text and NSUTF8StringEncoding
is one of many encoding options available.
문제
I have been trying to fix this for the past few hours and I cannot seem to get anything working. My question is straightforward, I need to convert some strings that are being inputted to a URL so that it correctly sends the spaces and special characters to the receiving server.
I have 3 strings: setFirstLast.text
, emailAddress.text
, and visitingTest.text
. I need to convert them into something that prints like: John%20Smith
instead of John Smith
.
해결책
You need to use
[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
to get the desired result. string
is the object containing your original text and NSUTF8StringEncoding
is one of many encoding options available.
다른 팁
Here, $url1 is your original url.
$url1 = "http://X.X.X.X/print/postToDB.php?namestamp=John Smith&emailstamp=john@example.com&visitingstamp=Bob Clark";
You could do:
$url2 = urlencode($url1);
//prints: http%3A%2F%2FX.X.X.X%2Fprint%2FpostToDB.php%3Fnamestamp%3DJohn%20Smith%26emailstamp%3Djohn%40example.com%26visitingstamp%3DBob%20Clark%0A
or
$url3 = str_replace(' ','%20', $url1);
//prints: http://X.X.X.X/print/postToDB.php?namestamp=John%20Smith&emailstamp=john@example.com&visitingstamp=Bob%20Clark
Does this help?