For some reasons, I would like to stick to using sprintf and I need to write into a file when each line has a tab space in the beginning. Here is what I wrote but it doesn’t work:
ff = open("test.txt", "w")
ss = Array{String, 0}
ss = @sprintf("\t o%-6d I : %9.6f, %9.6f", val[jj], 5.000000, -5.000000)
print(ff, ss)
instead of creating the space, it just writes “\t” into the file.
Why writing to an array of strings? You can write directly to the file:
julia> open("test.txt", "w") do io
for i in 1:5
@printf(io, "\t o%-6d I : %9.6f, %9.6f\n", i, rand(), -rand())
end
end
shell> cat test.txt
o1 I : 0.499033, -0.518227
o2 I : 0.452359, -0.057112
o3 I : 0.137529, -0.954224
o4 I : 0.792647, -0.996261
o5 I : 0.859669, -0.768580