How to update a NSString?
I want to ask a objective C question. I have a string retrieve from UITextField and I want to check the string contains the '@' or not. However, when I use the following code, it has some errors, can any开发者_JAVA技巧one help me? Thank you.
if([inputTextField.text rangeOfString:@"%"].location != NSNotFound)
NSLog(@"It does not contain the %@");
else
NSLog(@"It contains the %@");
Check the syntax:
if([inputTextField.text rangeOfString:myString].location == NSNotFound) NSLog(@"It does not contain the %@", myString); else NSLog(@"It contains the %@", myString);
As you will see, the %@
will be replaced with the content of myString
.
This code should do the trick:
if([inputTextField.text rangeOfString:@"@"].location == NSNotFound)
NSLog(@"It does not contain the @");
else
NSLog(@"It contains the @");
You can use
NSLog([NSString stringWithUTF8String: "It does not contain the @"]);
or just
NSLog(@"It contains the @");
Note: Inside the @"..." construct, you should only use 7-bit ASCII symbols, see Apple's developer documentation.
In you NSLog statement you put a %@ but no arguments after.
精彩评论