---
title: "tokenRange(at:unit:)"
framework: naturallanguage
role: symbol
role_heading: Instance Method
path: "naturallanguage/nltagger/tokenrange(at:unit:)"
---

# tokenRange(at:unit:)

Returns the range of the linguistic unit containing the specified character index.

## Declaration

```swift
@nonobjc func tokenRange(at index: String.Index, unit: NLTokenUnit) -> Range<String.Index>
```

## Parameters

- `unit`: The linguistic unit. For possible values, see doc://com.apple.naturallanguage/documentation/NaturalLanguage/NLTokenUnit.

## Return Value

Return Value The range of the substring for the linguistic unit.

## See Also

### Determining the range of a unit token

- [tokenRange(for:unit:)](naturallanguage/nltagger/tokenrange(for:unit:).md)
- [NLTokenUnit](naturallanguage/nltokenunit.md)
