Generic Instance Method

replace​Subrange(_:​with:​)

Replaces the text within the specified bounds with the given characters.

Declaration

mutating func replaceSubrange<C>(_ bounds: ClosedRange<String.Index>, with newElements: C) where C : Collection, C.Iterator.Element == Character

Parameters

bounds

The range of text to replace. The bounds of the range must be valid indices of the string.

new​Elements

The new characters to add to the string.

Discussion

Calling this method invalidates any existing indices for use with this string.

Complexity: O(m), where m is the combined length of the string and new​Elements. If the call to replace​Subrange(_:​with:​) simply removes text at the end of the string, the complexity is O(n), where n is equal to bounds.count.

Relationships

Generic Constraints

  • C : Collection
  • C.Iterator.Element == Character