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:

Create a list in SwiftUI with sticky section headers

 Sample Code import SwiftUI struct ContentView : View {     @State var isCustomViewControllerDisplayed = false     @State private va...