nextind returns the next valid index for an indexed collection or string. It matters because a character’s position in a Unicode string may skip code-unit positions. section 11.1.1
Walk a string safely
s = "Þrúðvangar"; i = firstindex(s); while i <= lastindex(s); println((i, s[i])); i = nextind(s, i); end. The indices progress 1, 3, 4, 6, 8, and so on, because some characters use multiple UTF-8 code units. section 11.1.1
For arrays, nextind is simply the current integer index plus one. For ordinary character iteration, for loops automatically advance by whole characters; use eachindex when the indices themselves are needed. section 11.1.1
Listing 11.1 Iterating over characters in a string using a while loop
julia> s = "Þrúðvangar"
julia> i = firstindex(s)
1
julia> while i <= lastindex(s)
println((i, s[i]))
i = nextind(s, i)
end
(1, 'Þ')
(3, 'r') #1
(4, 'ú')
(6, 'ð') #2
(8, 'v')
(9, 'a')
(10, 'n')
(11, 'g')
(12, 'a')
(13, 'r')
The runnable loop makes Unicode-aware index advancement visible. section 11.1.1
