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

# components(separatedBy:)

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

## Declaration

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

## Parameters

- `separator`: The separator string.

## Return Value

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

## Discussion

Discussion The substrings in the array appear in the order they did in the receiver. Adjacent occurrences of the separator string produce empty strings in the result. Similarly, if the string begins or ends with the separator, the first or last substring, respectively, is empty. For example, this code fragment: NSString *list = @"Karin, Carrie, David"; NSArray *listItems = [list componentsSeparatedByString:@", "]; produces the array @[@"Karin", @"Carrie", @"David"]. If list begins with a comma and space—for example, @", Norman, Stanley, Fletcher"—the array has these contents: @[@"", @"Norman", @"Stanley", @"Fletcher"]. If list has no separators—for example, @"Karin"—the array contains the string itself, in this case @[@"Karin"].

## See Also

### Related Documentation

- [pathComponents](foundation/nsstring/pathcomponents.md)
- [componentsJoined(by:)](foundation/nsarray/componentsjoined(by:).md)

### Dividing Strings

- [components(separatedBy:)](foundation/nsstring/components(separatedby:)-27x9g.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)
