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

# subscript(_:)

Accesses the code unit at the given position.

## Declaration

```swift
subscript(idx: String.UTF16View.Index) -> UTF16.CodeUnit { get }
```

## Overview

Overview The following example uses the subscript to print the value of a string’s first UTF-16 code unit. let greeting = "Hello, friend!" let i = greeting.utf16.startIndex print("First character's UTF-16 code unit: \(greeting.utf16[i])") // Prints "First character's UTF-16 code unit: 72"
