<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/AnyBidirectionalCollection/removingSubranges(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SlsE17removingSubrangesys18DiscontiguousSliceVyxGs8RangeSetVy5IndexQzGF::SYNTHESIZED::s:s26AnyBidirectionalCollectionV"
  },
  "title" : "removingSubranges(_:)"
}
-->

# removingSubranges(_:)

Returns a collection of the elements in this collection that are not
represented by the given range set.

```
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."
```

> Complexity: O(*n*), where *n* is the length of the collection.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)