Substring function?

Julia has a working substring functionality, which works on string indices.

The proposed character-indexing method does not eliminate the complexities of Unicode. Consider:

julia> substring(str, start, stop) = str[nextind(str, 0, start):nextind(str, 0, stop)]

julia> substring("äöü", 2,3) # NFC normalized string
"öü"

julia> substring("äöü", 2,3) # NFD normalized string
"̈o"

The supposed simplicity of “character indexing” is an illusion.

You pay a big price in performance to reduce apparent confusion on people’s first few days of using strings in Julia, but only postpone your Unicode bugs (because “characters” don’t mean what you think), and you get zero benefits in the long run (because indexing codepoint counts is not actually necessary for realistic string processing).

6 Likes