<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/String/UTF8View/subscript(_:)-6nubh",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SS8UTF8ViewVys5UInt8VSS5IndexVcip"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Accesses the code unit at the given position.

```
subscript(i: String.UTF8View.Index) -> UTF8.CodeUnit { get }
```

## Parameters

`i`

A valid index of the view. `i`
must be less than the view’s end index.

## Overview

The following example uses the subscript to print the value of a
string’s first UTF-8 code unit.

```
let greeting = "Hello, friend!"
let i = greeting.utf8.startIndex
print("First character's UTF-8 code unit: \(greeting.utf8[i])")
// Prints "First character's UTF-8 code unit: 72"
```

---

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)