String contains string in objective-c (iphone)
Posted
by Jonathan
on Stack Overflow
See other posts from Stack Overflow
or by Jonathan
Published on 2010-05-02T15:34:54Z
Indexed on
2010/05/02
15:37 UTC
Read the original article
Hit count: 743
How can I check if a string (NSString) contains another smaller string? I was hoping for something like:
NSString *string = @"hello bla bla";
NSLog(@"%d",[string containsSubstring:@"hello"]);
But the closest I could find was:
if ([string rangeOfString:@"hello"] == 0) {
NSLog(@sub string doesnt exist")
} else {
NSLog(@"exists")
}
I typed that straight into stack so sorry if there are errors, but there would be if I was doing it in Xcode so you don't need to point any out.
Anyway is that the best way to find if a string contains another string.
© Stack Overflow or respective owner