Print string on specific character position

Hi everyone, I’m trying to format some diagnostics for a Julia project I’m working on, and I was wondering if there’s a way to format strings such that the output is printed on a specific character position? For example, let’s say I have the following:

person = ["Adam" "Jennifer" "David"]
age = [25 34 57]

for i in zip(person, age)
    println(i[1] * "------" * string(i[2]))
end

which prints the following output:

Adam------25
Jennifer------34
David------57

My question is: is there a method to print ------ and i[2] on specific character positions? For example, if we say the beginning of each line is position zero, how would I go about printing the ------ starting on character position 12 and i[2] on character position 24?

Like this?

person = ["Adam" "Jennifer" "David"]
age = [25 34 57]

for i in zip(person, age)
    println(rpad(i[1], 12), "-" ^ 6, " " ^ 6, i[2])
end
Adam        ------      25
Jennifer    ------      34
David       ------      57
1 Like

yes, that’s exactly the formatting I’m looking for. Thank you!

1 Like

Fyi, Julia also allows writing the compact form:

@. println(rpad(person, 12, '-'), age);
2 Likes

Here is a Printf solution

using Printf

person = ["Adam" "Jennifer" "David"]
age = [25 34 57]

for i in 1:3
   @printf "%-12s%-12s%d\n" person[i] "-"^6 age[i]
end
Adam        ------      25
Jennifer    ------      34
David       ------      57
1 Like