<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSString/components(separatedBy:)-238fy",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)componentsSeparatedByString:"
  },
  "title" : "components(separatedBy:)"
}
-->

# components(separatedBy:)

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

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

## Parameters

`separator`

The separator string.

## Return Value

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

## 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:

```objc
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

[`pathComponents`](/documentation/Foundation/NSString/pathComponents)

The file-system path components of the receiver.

[`componentsJoined(by:)`](/documentation/Foundation/NSArray/componentsJoined(by:))

Constructs and returns an `NSString` object that is the result of interposing a given separator between the elements of the array.



---

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)