---
title: "distance(from:to:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/string/distance(from:to:)"
---

# distance(from:to:)

Returns the distance between two indices.

## Declaration

```swift
func distance(from start: String.Index, to end: String.Index) -> Int
```

## Parameters

- `start`: A valid index of the collection.
- `end`: Another valid index of the collection. If end is equal to start, the result is zero.

## Return Value

Return Value The distance between start and end.

## Discussion

Discussion note: O(n), where n is the resulting distance.

## See Also

### Manipulating Indices

- [startIndex](swift/string/startindex.md)
- [endIndex](swift/string/endindex.md)
- [index(after:)](swift/string/index(after:).md)
- [formIndex(after:)](swift/string/formindex(after:).md)
- [index(before:)](swift/string/index(before:).md)
- [formIndex(before:)](swift/string/formindex(before:).md)
- [index(_:offsetBy:)](swift/string/index(_:offsetby:).md)
- [index(_:offsetBy:limitedBy:)](swift/string/index(_:offsetby:limitedby:).md)
- [formIndex(_:offsetBy:)](swift/string/formindex(_:offsetby:).md)
- [formIndex(_:offsetBy:limitedBy:)](swift/string/formindex(_:offsetby:limitedby:).md)
- [indices](swift/string/indices-swift.property.md)
