Julia’s join combines the elements of any iterable into text. Without a separator, it concatenates values directly; with one, it places that separator between elements. section 4.8 section 11.2.1
Useful forms include:
- join(['H', 'E', 'L', 'L', 'O']) returns "HELLO". section 4.8
- join('A':2:'G') returns "ACEG", showing that ranges are valid iterables. section 4.8
- join(words, '_') combines collected words with underscores, turning separated camel-case words into snake case. section 11.2.1
- join(io, row, ',') writes comma-separated values directly to an I/O object instead of returning a string. section 17.4.2
Create a snake-case name
Collect the words from a camel-case string, lowercase them, and join them with an underscore: `words = ["one", "Two", "Three", "Four"]`; `join(lowercase.(words), '_')` produces `"one_two_three_four"`. section 11.2.1
Listing 17.5 An io.jl file with added save_engines code
function save_engines(path::AbstractString, engines)
open(path, "w") do io
println(io, "name,company,mass,thrust,Isp")
for (name, egn) in engines
row = [name, "", egn.mass, egn.thrust, egn.Isp]
join(io, row, ',')
println(io)
end
end
end
Inspect a practical file-writing utility that uses join to serialize rocket-engine rows as comma-separated data. section 17.4.2
