Structure

String.Index

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

Declaration

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

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 or equal to 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 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.