How do I check if a string contains another string in Swift?

后端 未结 27 3327
天命终不由人
天命终不由人 2020-11-22 12:32

In Objective-C the code to check for a substring in an NSString is:

NSString *string = @\"hello Swift\";
NSRange textRange =[strin         


        
27条回答
  •  盖世英雄少女心
    2020-11-22 13:18

    In iOS 8 and newer, you can use these two NSString methods:

    @availability(iOS, introduced=8.0)
    func containsString(aString: String) -> Bool
    
    @availability(iOS, introduced=8.0)
    func localizedCaseInsensitiveContainsString(aString: String) -> Bool
    

提交回复
热议问题