Structure

String.Index

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

Declaration

@frozen struct Index

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.Index, within: String.UnicodeScalarView)

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

init?<S>(String.Index, within: S)

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

init(encodedOffset: Int)

Creates a new index at the specified code unit offset.

Deprecated
init<S>(utf16Offset: Int, in: S)

Creates a new index at the specified UTF-16 code unit offset

Instance Properties

var encodedOffset: Int

The offset into a string’s code units for this index.

Deprecated
var hashValue: Int

The hash value.

Instance Methods

func hash(into: inout Hasher)

Hashes the essential components of this value by feeding them into the given hasher.

func samePosition(in: String) -> String.Index?

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

func samePosition(in: String.UTF8View) -> String.UTF8View.Index?

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

func samePosition(in: String.UnicodeScalarView) -> String.UnicodeScalarIndex?

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

func samePosition(in: String.UTF16View) -> String.UTF16View.Index?

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

func utf16Offset<S>(in: S) -> Int

The UTF-16 code unit offset corresponding to this Index

Operator Functions

static func != (String.Index, String.Index) -> Bool

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

static func ... (String.Index) -> PartialRangeFrom<String.Index>

Returns a partial range extending upward from a lower bound.

static func ... (String.Index) -> PartialRangeThrough<String.Index>

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

static func ... (String.Index, String.Index) -> ClosedRange<String.Index>

Returns a closed range that contains both of its bounds.

static func ..< (String.Index) -> PartialRangeUpTo<String.Index>

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

static func ..< (String.Index, String.Index) -> Range<String.Index>

Returns a half-open range that contains its lower bound but not its upper bound.

static func < (String.Index, String.Index) -> Bool

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

static func <= (String.Index, String.Index) -> Bool

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) -> Bool

Returns a Boolean value indicating whether two values are equal.

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

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) -> Bool

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

Relationships

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.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.

struct String.Iterator

A type that provides the collection’s iteration interface and encapsulates its iteration state.