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

# lineRange(for:)

Returns the range of characters representing the line or lines containing a given range.

```
func lineRange(for range: NSRange) -> NSRange
```

## Parameters

`range`

A range within the receiver. The value must not exceed the bounds of the receiver.

## Return Value

The range of characters representing the line or lines containing `aRange`, including the line termination characters. See [`getLineStart(_:end:contentsEnd:for:)`](/documentation/Foundation/NSString/getLineStart(_:end:contentsEnd:for:)) for a discussion of line terminators.

## See Also

[`-  substringWithRange:`](/documentation/Foundation/NSString/substring(with:))

Returns a string object containing the characters of the receiver that lie within a given range.



---

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)