---
title: "attributedSubstring(from:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsattributedstring/attributedsubstring(from:)"
---

# attributedSubstring(from:)

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

## Declaration

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

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

## Discussion

Discussion Raises an 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.

## See Also

### Getting the characters

- [string](foundation/nsattributedstring/string.md)
- [length](foundation/nsattributedstring/length.md)
