escape % in iOS to write sql [duplicate] - ios

This question already has an answer here:
escape % in objective c
(1 answer)
Closed 8 years ago.
I want to write sql query in NSString, the query is:
WHERE fa_name LIKE '%anyValue%'
I wrote the following code
NSString *whereFamilyName = [NSString stringWithFormat:#"fa_name LIKE '\%%#\%'", typedFamilyName];
but it doesn't escape the % and the output is:
fa_name LIKE '%#'

To Escape a % simply write two %%.
NSString *string = [NSString stringWithFormat:#"fa_name LIKE '%%%#%%'", #"val"];

Related

NSString stringWithFormat less parameters [duplicate]

This question already has an answer here:
Multiple arguments in stringWithFormat: “n$” positional specifiers
(1 answer)
Closed 7 years ago.
We need to format a string, but for some localisations we won't output all parameters. But it seems that it doesn't work to output less parameters than passed:
NSString *string = [NSString stringWithFormat: #"%2$#", #"<1111>", #"<22222>"];
NSLog(#"String = %#", string);
Outputs
String = <1111>
although i output the second parameter.
Is this a bug or a feature?
according to the related industrial standard, IEEE specification:
When numbered argument specifications are used, specifying the Nth argument requires that all the leading arguments, from the first to the (N-1)th, are specified in the format string.
which means in other words, you must use the first %1$# parameter in your string formatter somewhere before you address to use the second one – so, it is not a bug at all.

Reading exact text from the "Tj/TJ" operator of CGPDFDictionaryRef [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying to read text from the "Tj/TJ" operator of CGPDFDictionary, but the TJ/Tj operator has the text in (encoded) format for e.g,
Tj = <00><1F><05>. Now i want to get this exact text in NSString i.e NSString should contain "<00><1F><05>".I tried to get the content from TJ/Tj in CGPDFStringRef, but when i am trying to put it in const unsigned char* using CGPDFStringGetBytePtr or in NSString using CGPDFStringCopyTextString i am not getting the desired output. Please suggest me a solution.
Got the answer:
size_t length = CGPDFStringGetLength(string);
NSData *oprData = [NSData dataWithBytes:CGPDFStringGetBytePtr(string) length:length];
NSString *hexString = [[NSString stringWithFormat:#"%#",oprData] uppercaseString];
Here string is the CGPDFStringRef. Finally we get the content of Tj/TJ operator in hexString variable.

Checking the format of characters within a postcode [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am constructing a form and have managed to sort out the input in the form. What I am attempting to do is when an entry is inputed for the postcode it does a check to make sure it follows a pre determined format.
So far I have removed the space, made 2 character sets, one with numerical values and one with just letters. And then done a check on the string length. This is below:-
NSCharacterSet *cset = [NSCharacterSet characterSetWithCharactersInString:#"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];
NSCharacterSet *nset = [NSCharacterSet characterSetWithCharactersInString:#"1234567890"];
_QuestionAnswer.text = [_QuestionAnswer.text stringByReplacingOccurrencesOfString:#" " withString:#""]; //removes the space character
if (4 < _QuestionAnswer.text.length < 8) //checks string length between 5 and 7
{
// this is where the format check should be done using cset and nset
}
NB UK post codes must follow any one of the example formats below:-
AA9A 9AA,
A9A 9AA,
A9 9AA,
A99 9AA,
AA9 9AA,
AA99 9AA,
Where 'A' is from cset and '9' is from nset
Thank you in advance.
You can use regular expressions (my is just example):
NSString *laxString = #".+#([A-Za-z0-9]+\\.)";
NSPredicate *postCodeTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", laxString];
return [postCode evaluateWithObject: postCodeTest];

Unichar with specific characters [duplicate]

This question already has answers here:
Objective c doesn't like my unichars?
(3 answers)
Closed 9 years ago.
I'm trying to add some specific characters to my
unichar rusLetter [] = { 'Ж', 'Й', }
I want actually to add all letters from russian alphabet. Using above line of code, i get an error:
Character too large for enclosing character literal type
Any ideas how to fix that? And maybe there is an easier way to add all letters, not to type all of them.
Thanks
the ' literal (single quote) means a char and that is too small to hold the symbols.
In ObjC use an NSString to hold it
NSString *rusLetters = #"ЖЙ";
unichar c1 = [rusLetters characterAtIndex:0];
unichar c2 = [rusLetters characterAtIndex:1];

NSLog symbol print on console? [duplicate]

This question already has answers here:
How to add percent sign to NSString
(7 answers)
Closed 9 years ago.
How to print symbol "%" in NSLog ???
NSLog(#"str %");
It gives warning
incomplete format specifier
How to resolve this problem?
try this
NSLog(#"str : %%");
Thanks
Just use two percent signs:
NSLog(#"str %%"); //prints "str %"
Here is the list of format specifiers for all types of data printing which can be useful for iOS programming.
You need to print like this
NSLog(#"%%");
use this code
NSLog(#"str %%");

Resources