I have a search field, which is a UITextView
, where the user enters data that will be searched in a MySQL database in a server.
The search and PHP that Xcode calls work for normal characters, but the encoding I am doing does not seem to work correctly for special characters such as ā, as an example. I have managed to save data with special characters to the MySQL database, but for some reason the code I am doing to search does not seem to encode the data correctly.
the current code I have is:
NSString *searchString;
searchString = [searchTextField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
searchString = [searchString stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
searchTextField.text
is a UITextView
. Any ideas why this is not working?
OK - I have solved the problem BUT I don't understand why. So would be grateful for explanations.
The way I have solved the problem, which by the way seems to be like using a hammer to crack a nut, is by saving the string I am searching in a SQLite database. Once saved, it is assigned to searchString and it gets encoded properly.
Can someone explain why this is the case?