Arrays 朱莉娅:数组元素的字符串插值

Arrays 朱莉娅:数组元素的字符串插值,arrays,julia,Arrays,Julia,我可以将一个变量插入到字符串中,用其他文本打印值,如下所示: a = "sheriff"; println("Howdy, I'm the $a.") Howdy, I'm the sheriff. 我需要插入数组元素的语法,我现在得到: A = ["carb", "sheriff", "mumchance"] println("Howdy, I'm the $A[2].") Howdy, I'm the String["carb", "sheriff", "mumchance"][2].

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

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

Howdy, I'm the sheriff.
我需要插入数组元素的语法,我现在得到:

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

Howdy, I'm the String["carb", "sheriff", "mumchance"][2].

我发布这个Q/A是因为我花了太多时间寻找这个

println("Howdy, I'm the $(A[2]).")
Julia中的字符串插值类似于unixshell。可以通过将表达式括在括号中来插入表达式


谢谢,在看到这个答案之前,我也看了很久。值得注意的是,这同样适用于处理字典时的
println(“你好,我是$(A[“key”])”)