<!--
{
  "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/UnicodeScalarView/subscript(_:)-2op53",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SS17UnicodeScalarViewVys0A0O0B0VSS5IndexVcip"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Accesses the Unicode scalar value at the given position.

```
subscript(position: String.UnicodeScalarView.Index) -> Unicode.Scalar { get }
```

## Parameters

`position`

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

## Overview

The following example searches a string’s Unicode scalars view for a
capital letter and then prints the character and Unicode scalar value
at the found index:

```
let greeting = "Hello, friend!"
if let i = greeting.unicodeScalars.firstIndex(where: { "A"..."Z" ~= $0 }) {
    print("First capital letter: \(greeting.unicodeScalars[i])")
    print("Unicode scalar value: \(greeting.unicodeScalars[i].value)")
}
// Prints "First capital letter: H"
// Prints "Unicode scalar value: 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)