rangeOfString
rangeOfString is a method used in Cocoa and Cocoa Touch to locate a substring within an NSString. It returns an NSRange describing the location and length of the first occurrence of the specified string in the receiver. If the substring is not found, the returned range has a location of NSNotFound.
There are several overloads of the method. Common signatures include: - (NSRange)rangeOfString:(NSString *)aString; - (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask;
Return value: An NSRange with the location and length of the found substring. If not found, location
Usage considerations: By default the search is case-sensitive and diacritic-sensitive. To perform case-insensitive searches, include NSCaseInsensitiveSearch
Swift and bridge: In Swift, String provides range(of:) returning an optional Range<String.Index>, and NSString’s rangeOfString methods