Monday, June 04, 2012

String matching and comparison

NSString* str1 = @"hello";
NSString* str2 = @"hello world";
NSRange matching = [str2 rangeOfString : str1];

// Searching for a string within another string
if(matching.location == NSNotFound){
    // str1 not found in str2
} else {
    // str1 found in str2
}

// Checking for equality
if([str1 isEqualToString:@"hello"]){
    // str1 is equal to "hello"
} else {
    // str1 is not equal to "hello"
}

No comments:

Swift Operators - Basic Part 3 (Range operators in swift)

Range Operators: Closed Range operators  Half-Open Range Operators One-Sided Ranges Closed Range Operators:  a...b It defines...