Swift is there a method that gives the index of a substring inside another string
问题 Is there any existing function that looks for the index of a substring inside another string? A method like .indexOfSubstring thank does this: let word: String = "Hey there, how are you?" let indexOf: Int = word.indexOfSubstring("ere, how are") println("index = " + \(indexOf)) and prints: index = 6 回答1: You can use the rangeOfString method: import Foundation let word: String = "Hey there, how are you?" if let range = word.rangeOfString("ere, how are") { let index = distance(word.startIndex,