Structure

String.Index

A position of a character or code unit in a string.

Topics

Initializers

init?(String.Index, within: String.UTF16View)

Creates an index in the given UTF-16 view that corresponds exactly to the specified string position.

init?(String.Index, within: String.UTF8View)

Creates an index in the given UTF-8 view that corresponds exactly to the specified UTF16View position.

init?(String.Index, within: String)

Creates an index in the given string that corresponds exactly to the specified position.

init?(String.UTF16Index, within: String.UnicodeScalarView)

Creates an index in the given Unicode scalars view that corresponds exactly to the specified UTF16View position.

init(encodedOffset: Int)

Creates a new index at the specified UTF-16 offset.

Instance Properties

var encodedOffset: Int

The offset into a string’s UTF-16 encoding for this index.

Instance Methods

func samePosition(in: String)

Returns the position in the given string that corresponds exactly to this index.

func samePosition(in: String.UTF8View)

Returns the position in the given UTF-8 view that corresponds exactly to this index.

func samePosition(in: String.UnicodeScalarView)

Returns the position in the given view of Unicode scalars that corresponds exactly to this index.

func samePosition(in: String.UTF16View)

Returns the position in the given UTF-16 view that corresponds exactly to this index.

Operator Functions

static func !=(String.Index, String.Index)

Returns a Boolean value indicating whether two values are not equal.

static func ...(String.Index)

Returns a partial range extending upward from a lower bound.

static func ...(String.Index)

Returns a partial range up to, and including, its upper bound.

static func ..<(String.Index)

Returns a partial range up to, but not including, its upper bound.

static func <=(String.Index, String.Index)

Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.

static func >(String.Index, String.Index)

Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.

static func >=(String.Index, String.Index)

Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.

Relationships

Conforms To

See Also

Related String Types

struct Substring

A slice of a string.

protocol StringProtocol

A type that can represent a string as a collection of characters.

struct String.CharacterView

A view of a string’s contents as a collection of characters.

Deprecated
struct String.UnicodeScalarView

A view of a string’s contents as a collection of Unicode scalar values.

struct String.UTF16View

A view of a string’s contents as a collection of UTF-16 code units.

struct String.UTF8View

A view of a string’s contents as a collection of UTF-8 code units.