String subscript given as integer



I’d like to write a function f(n::Int)::String such that f(1) = "x₁", f(2) = "x₂" and so on (assume 1<=n<=9 for simplicity). Since

julia> 'x' * '\u2081'

Let n=3; the syntax 'x' * '\u' * string(n + 2080) is invalid: ERROR: syntax: invalid escape sequence. The backslash can be escaped with “raw”, but how can i get the subscript back?

julia> 'x' * raw"\u" * "$(n + 2080)"


This works

julia> foo(i) = "x" * Char(0x2080 + i)
foo (generic function with 1 method)

julia> foo(1)

julia> foo(2)

julia> foo(3)


Great, thanks!