replaceOccurrences(of:with:options:range:)
Replaces all occurrences of a given string in a given range with another given string, returning the number of replacements.
Declaration
func replaceOccurrences(of target: String, with replacement: String, options: NSString.CompareOptions = [], range searchRange: NSRange) -> IntParameters
- target:
The string to replace.
- replacement:
The string with which to replace
target. - options:
A mask specifying search options. See 10000035i for details.
If
optsisNSBackwardsSearch, the search is done from the end of the range. IfoptsisNSAnchoredSearch, only anchored (but potentially multiple) instances are replaced.NSLiteralSearchandNSCaseInsensitiveSearchalso apply. - searchRange:
The range of characters to replace.
searchRangemust not exceed the bounds of the receiver. SpecifysearchRangeasNSMakeRange(0, [receiver length])to process the entire string.
Return Value
The number of replacements made.
Discussion
This method treats the length of the string as a valid range value that returns an empty string.