---
title: "subscript(_:)"
framework: swift
role: symbol
role_heading: Instance Subscript
path: "swift/string/subscript(_:)-lc0v"
---

# subscript(_:)

Accesses the character at the given position.

## Declaration

```swift
subscript(i: String.Index) -> Character { get }
```

## Parameters

- `i`: A valid index of the string. i must be less than the string’s end index.

## Overview

Overview You can use the same indices for subscripting a string and its substring. For example, this code finds the first letter after the first space: let str = "Greetings, friend! How are you?" let firstSpace = str.firstIndex(of: " ") ?? str.endIndex let substr = str[firstSpace...] if let nextCapital = substr.firstIndex(where: { $0 >= "A" && $0 <= "Z" }) {     print("Capital after a space: \(str[nextCapital])") } // Prints "Capital after a space: H"

## See Also

### Getting Characters and Bytes

- [first](swift/string/first.md)
- [last](swift/string/last.md)
- [randomElement()](swift/string/randomelement().md)
- [randomElement(using:)](swift/string/randomelement(using:).md)
