samlerepo/Code/14.IOBuffer.jl

16 lines
388 B
Julia
Raw Normal View History

2019-09-12 16:32:16 +02:00
# IOBuffers are like writing to a file in memory. They are really efficient
# when creating strings and work like any other IO object we've worked with.
io = IOBuffer()
a = 42
write(io, "i = ")
print(io, a)
# To retrieve the written data from the buffer we call take!(). This returns
# a Vector{UInt8} so to interpret it as a string we call String()
s = String(take!(io))
println(s)