Searches for a substring within a range of the characters represented by a string and, if the substring is found, returns its range within the object's characters.


Boolean CFStringFindWithOptions(CFStringRef theString, CFStringRef stringToFind, CFRange rangeToSearch, CFStringCompareFlags searchOptions, CFRange *result);



The string in which to to search for stringToFind.


The substring to search for in theString.


A range of the characters to search in theString. The specified range must not exceed the length of the string.


The option flags to control the search behavior. See String Comparison Flags for possible values. The flags kCFCompareNumerically and kCFCompareForcedOrdering are ignored.


On return, if the function result is true, contains the starting location and length of the found substring. You may pass NULL if you only want to know if the substring exists in the larger string.

Return Value

true if the substring was found, false otherwise.


This function allows you to search only part of the characters of a string for a substring. It returns the found range indirectly, in the final result parameter. If you want to know if the entire range of characters represented by a string contains a particular substring, you can use the convenience function CFStringFind. Both of these functions return upon finding the first occurrence of the substring, so if you want to find out about multiple occurrences, call the CFStringCreateArrayWithFindResults function.

Depending on the comparison-option flags specified, the length of the resulting range might be different than the length of the search string.

See Also

Searching Strings


Searches a string for multiple occurrences of a substring and creates an array of ranges identifying the locations of these substrings within the target string.


Searches for a substring within a string and, if it is found, yields the range of the substring within the object's characters.


Query the range of the first character contained in the specified character set.


Returns a Boolean value that indicates whether a given string was found in a given source string.


Given a range of characters in a string, obtains the line bounds—that is, the indexes of the first character and the final characters of the lines containing the range.