---
title: "components(separatedBy:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/components(separatedby:)-27x9g"
---

# components(separatedBy:)

Returns an array containing substrings from the receiver that have been divided by characters in a given set.

## Declaration

```swift
func components(separatedBy separator: CharacterSet) -> [String]
```

## Parameters

- `separator`: A character set containing the characters to use to split the receiver. Must not be nil.

## Return Value

Return Value An NSArray object containing substrings from the receiver that have been divided by characters in separator.

## Discussion

Discussion The substrings in the array appear in the order they did in the receiver. Adjacent occurrences of the separator characters produce empty strings in the result. Similarly, if the string begins or ends with separator characters, the first or last substring, respectively, is empty.

## See Also

### Dividing Strings

- [components(separatedBy:)](foundation/nsstring/components(separatedby:)-238fy.md)
- [trimmingCharacters(in:)](foundation/nsstring/trimmingcharacters(in:).md)
- [substring(from:)](foundation/nsstring/substring(from:).md)
- [substring(with:)](foundation/nsstring/substring(with:).md)
- [substring(to:)](foundation/nsstring/substring(to:).md)
