Replaces all occurrences of a substring within a given range.
- iOS 2.0+
- macOS 10.2+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Core Foundation
The string to modify.
The substring to search for in
The replacement string for
The range within which to search in
Flags that select different types of comparisons, such as localized comparison, case-insensitive comparison, and non-literal comparison. If you want the default comparison behavior, pass
CFStringfor the available flags.
The number of instances of
string that were replaced.
k option can be used to replace a substring starting from the end, which could produce different results. For example, if the parameter
the is “AAAAA”,
string is “AA”, and
replacement is “B”, then the result is normally “BBA”. However, if the
k constant is used, the result is “ABB.”
k option assures that only anchored but multiple instances are found (the instances must be consecutive at start or end). For example, if the parameter
the is “AAXAA”,
string is “A”, and
replacement is “B”, then the result is normally “BBXBB.” However, if the
k constant is used, the result is “BBXAA.”