I am making a string that is being used in a SQL statement. I need to reuse the same string within it several times. This string is the text from a textbox.
Current Code:
NSString *searchStr = [NSString stringWithFormat:@"(Name LIKE \'%%%@%%\' OR Contact LIKE \'%%%@%%\')", [self.txtfSearch text], [self.txtfSearch text]];
All the %'s are for a contains search. Please no comments on this method as I am connecting to a webservice that I have no control over currently. Im sure you can all relate.
What I need to do is reuse the [self.txtfSearch text] part at the end. I have looked up the apple dev docs on strings and placeholders. I even tried the C# method of using {0} for the placeholder but I cant get it working.
Doing it as above isnt a big deal if im looking in 2 columns, but there are many cases where its going to be 6 or more and then the string building gets ridiculous.
I want something like this:
NSString *searchStr = [NSString stringWithFormat:@"(Name LIKE \'%%{0}%%\' OR Contact LIKE \'%%{0}%%\')", [self.txtfSearch text]];
Is there a way to do this in obj-c?