Julia:数组元素的字符串插值

Mer*_*lin 3 arrays julia

我可以将变量插入字符串中,以使用其他文本打印该值,如下所示:

a = "sheriff";
println("Howdy, I'm the $a.")

Howdy, I'm the sheriff.
Run Code Online (Sandbox Code Playgroud)

我需要插入数组元素的语法,我目前得到的是:

A = ["carb", "sheriff", "mumchance"]
println("Howdy, I'm the $A[2].")

Howdy, I'm the String["carb", "sheriff", "mumchance"][2].
Run Code Online (Sandbox Code Playgroud)

Mer*_*lin 5

我发布这个问答是因为我花了太多时间寻找这个问题。

println("Howdy, I'm the $(A[2]).")
Run Code Online (Sandbox Code Playgroud)

Julia 中的字符串插值类似于 unix shell。您可以通过将表达式括在括号中来插入表达式。

Julia 文档:字符串/插值