removingSubranges(_:)
Returns a collection of the elements in this collection that are not represented by the given range set.
Declaration
func removingSubranges(_ subranges: RangeSet<Self.Index>) -> DiscontiguousSlice<Self>Parameters
- subranges:
A range set representing the indices of the elements to remove.
Return Value
A collection of the elements that are not in subranges.
Discussion
For example, this code sample finds the indices of all the vowel characters in the string, and then retrieves a collection that omits those characters.
let str = "The rain in Spain stays mainly in the plain."
let vowels: Set<Character> = ["a", "e", "i", "o", "u"]
let vowelIndices = str.indices(where: { vowels.contains($0) })
let disemvoweled = str.removingSubranges(vowelIndices)
print(String(disemvoweled))
// Prints "Th rn n Spn stys mnly n th pln."