2
votes

I can interpolate a variable into a string to print the value with other text like this:

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

Howdy, I'm the sheriff.

I need the syntax for interpolating an array element, I'm currently getting this:

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

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

1 Answers

3
votes

I'm posting this Q/A because I spent too much time looking for this.

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

String interpolation in Julia is similar to unix shells. You can interpolate expressions by wrapping them in parentheses.

Julia Documentation: Strings/Interpolation