Instance Subscriptswift 6.0.1Swift
subscript(_:)
Accesses the code unit at the given position.
subscript(i: String.UTF8View.Index) -> UTF8.CodeUnit { get }
Parameters
- position
A valid index of the view.
position
must be less than the view’s end index.
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"
Other members in extension
Typealiases
Instance members
var count: Int
var customMirror: Mirror
Returns a mirror that reflects the UTF-8 view of a string.
var debugDescription: String
var description: String
var endIndex: String.UTF8View.Index
The “past the end” position—that is, the position one greater than the last valid subscript argument.
var startIndex: String.UTF8View.Index
The position of the first code unit if the UTF-8 view is nonempty.
subscript(Range<String.UTF8View.Index>
) -> String.UTF8View.SubSequence func distance(from: String.UTF8View.Index, to: String.UTF8View.Index
) -> Int func index(String.UTF8View.Index, offsetBy: Int
) -> String.UTF8View.Index func index(String.UTF8View.Index, offsetBy: Int, limitedBy: String.UTF8View.Index
) -> String.UTF8View.Index? func index(after: String.UTF8View.Index
) -> String.UTF8View.Index Returns the next consecutive position after
i
.func index(before: String.UTF8View.Index
) -> String.UTF8View.Index func withContiguousStorageIfAvailable<R>((UnsafeBufferPointer<String.UTF8View.Element>) throws -> R
) rethrows -> R?