IOBuffer is what you're looking for:

buf = IOBuffer()
for i = 1:100
    println(buf, i)
end
takebuf_string(buf) # => returns everything that's been written to buf.

The takebuf_string function really needs a new name.

On Tue, Feb 17, 2015 at 9:06 AM, Maurice Diamantini <
[email protected]> wrote:

> Hi,
>
> In Ruby, String is mutable which allows to build large strings like this:
>     txt = ""
>     for ...
>         txt << "yet another line\n"
>     end
>     # do something with txt
>
> The Julia the (bad) way I use is to do:
>     txt = ""
>     for ...
>         txt *=  "yet another line\n"
>     end
>     # do something with txt
>
> Which is very slow for a big string (because it build a new more and more
> string at each iteration).
>
> So is there another way to do it (in standard Julia)?
> Or is there another type which could be used (something like a Buffer type
> or Array type)?
>
> Thank,
> -- Maurice
>

Reply via email to