0

I am posting to a NSURL using the new NSCharacterSet to allow spaces and different characters which would otherwise cause the app to crash upon posting. I have come across an issue, whenever I have an apostrophe(') in the text I am posting it causes the app to crash. Code below is what I am using to convert the text box to post it. I have tried most characters and nothing causes it to crash so I don't understand why the apostrophe does. Anyone come across the same issue??

NSString *text = [self.textbox.text stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
Atanu Mondal
  • 1,714
  • 1
  • 24
  • 30
Curtis Boylan
  • 827
  • 1
  • 7
  • 23

1 Answers1

1

I have found a solution to what I asked, it was nothing to do with the objective c itself but the php I was posting to. You cannot insert a single apostrophe into a mysql database so you need to replace the apostrophe with a double and it will show as a single.

You can do this with the following code:

NSString *newmessage = [self.textbox.text stringByReplacingOccurrencesOfString:@"'"
                                     withString:@"''"];

I hope this will help anyone with a similar issue.

Curtis Boylan
  • 827
  • 1
  • 7
  • 23