Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia: String interpolation of Array element

Tags:

arrays

julia

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].
like image 715
Merlin Avatar asked Oct 18 '25 03:10

Merlin


1 Answers

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

like image 84
Merlin Avatar answered Oct 20 '25 19:10

Merlin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!