<!--
{
  "availability" : [
    "iOS: 3.2.0 -",
    "iPadOS: 3.2.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreText",
  "identifier" : "/documentation/CoreText/CTLineGetOffsetForStringIndex(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Text"
    ],
    "preciseIdentifier" : "c:@F@CTLineGetOffsetForStringIndex"
  },
  "title" : "CTLineGetOffsetForStringIndex(_:_:_:)"
}
-->

# CTLineGetOffsetForStringIndex(_:_:_:)

Determines the graphical offset or offsets for a string index.

```
func CTLineGetOffsetForStringIndex(_ line: CTLine, _ charIndex: CFIndex, _ secondaryOffset: UnsafeMutablePointer<CGFloat>?) -> CGFloat
```

## Parameters

`line`

The line from which the offset is requested.

`charIndex`

The string index corresponding to the desired position.

`secondaryOffset`

On output, the secondary offset along the baseline for `charIndex`. When a single caret is sufficient for a string index, this value will be the same as the primary offset, which is the return value of this function. May be `NULL`.

## Return Value

The primary offset along the baseline for `charIndex`, or `0.0` if the line does not support string access.

## Discussion

This function returns the graphical offset or offsets corresponding to a string index, suitable for movement between adjacent lines or for drawing a custom caret. For moving between adjacent lines, the primary offset can be adjusted for any relative indentation of the two lines; a <doc://com.apple.documentation/documentation/CoreFoundation/CGPoint> constructed with the adjusted offset for its `x` value and `0.0` for its `y` value is suitable for passing to [`CTLineGetStringIndexForPosition(_:_:)`](/documentation/CoreText/CTLineGetStringIndexForPosition(_:_:)). For drawing a custom caret, the returned primary offset corresponds to the portion of the caret that represents the visual insertion location for a character whose direction matches the line’s writing direction.

---

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)