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

后端 未结 27 3795
天命终不由人
天命终不由人 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:14

    Here you are:

    let s = "hello Swift"
    if let textRange = s.rangeOfString("Swift") {
        NSLog("exists")
    }
    

提交回复
热议问题