The index(after:)
method in Swift returns the position immediately after the given index. The after
in this method refers to the index of the character that comes directly after the given index.
str.index(after:i)
i
: This is a valid index of the collection. It must be less than the endIndex
property.
This method returns the index value that comes immediately after i
.
// create some stringslet name = "Theodore"let language = "Swift"// get some indexlet index1 = name.index(after:name.startIndex)let index2 = language.index(after:language.startIndex)// access the index in the stringprint(name[index1])print(language[index2])
name
and language
.index(after:)
method.