-1

I have a Text View which will be used to input data on multiple lines. The string will then be posted to an URL to a php file and then to a MYSQL Database.

The problem i am having is that the string will not be send if i use multiple lines. I used the following to get around the fact that (Spaces) could not be sent via a URL:

hostStr = [hostStr stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

Is there anything similar to this I can do to get the string to return with multiple lines?

Awais Hussain
  • 2,400
  • 2
  • 12
  • 11

1 Answers1

0

Have you tried [hostStr stringByAddingPercentEscapesUsingEncoding:] ?

Marcin P
  • 11
  • 3
  • This is not adequate. It takes care of spaces and newline characters, but it won't percent escape other characters that need encoding (notably `+` or `&` would be problematic if they ever appeared in the string). – Rob Jan 07 '15 at 13:49
  • Good point. I think `[hostStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet alphanumericCharacterSet]]` would be better – Marcin P Jan 08 '15 at 07:06
  • Yep. Technically, [RFC 3986](http://tools.ietf.org/html/rfc3986) qualifies this and instructs us that the only characters that should never be percent escaped are the unreserved characters, include `alphanumericCharacterSet` plus "-", ".", "_", and "~". So I would advise adding those four character to the allowed characters set (though, in practice, it really doesn't matter). – Rob Jan 08 '15 at 12:54