Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top