Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

swift
index
string
communitycreator

What is the endIndex property of a string in Swift?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

In Swift, the endIndex property is used to get a past-the-end position. This means that the position one is greater than the last valid subscript argument. If the string is empty, it returns startIndex.

Syntax

string.endIndex

Return value

This property returns the past-the-end position of a string.

Example

// print some strig endIndex property values
print("hello".endIndex)
print("welcome".endIndex)
print("to".endIndex)
print("Edpresso!".endIndex)
Get the endIndex property of string values

Explanation

  • Line 2–5: We use the endIndex property on the strings and print the results to the console.

RELATED TAGS

swift
index
string
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring