<!--
{
  "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/NSAttributedString/attributedSubstring(from:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAttributedString(im)attributedSubstringFromRange:"
  },
  "title" : "attributedSubstring(from:)"
}
-->

# attributedSubstring(from:)

Returns an attributed string consisting of the characters and attributes within the specified range in the attributed string.

```
func attributedSubstring(from range: NSRange) -> NSAttributedString
```

## Parameters

`range`

The range from which to create a new attributed string. `aRange` must lie within the bounds of the receiver.

## Return Value

An `NSAttributedString` object consisting of the characters and attributes within `aRange` in the receiver.

## Discussion

Raises an [`rangeException`](/documentation/Foundation/NSExceptionName/rangeException) if any part of `aRange` lies beyond the end of the receiver’s characters. This method treats the length of the string as a valid range value that returns an empty string.

---

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)