# Printing to string from stream

**URL:** <https://discourse.julialang.org/t/printing-to-string-from-stream/29689>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [October 9, 2019, 6:23pm UTC](https://discourse.julialang.org/t/printing-to-string-from-stream/29689 "2019-10-09T18:23:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajesh\_Talluri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rajesh_talluri/32/10721_2.png) [@Rajesh\_Talluri](https://discourse.julialang.org/u/Rajesh_Talluri)\
**Post date:** [October 9, 2019, 6:23pm UTC](https://discourse.julialang.org/t/printing-to-string-from-stream/29689/1 "2019-10-09T18:23:12Z")

</div>

Hi,  
I am trying to get the output of a stream into a string. For example  
the `highlight` function outputs the result to an IO object, so I can open a file and write to it. I can also get it printed using stdout.

However, I just need to store it in a string. Can someone please let me know how to accomplish this.

```julia
using Highlights
highlight(stdout, MIME("text/html"), "a = 1+2", Lexers.JuliaLexer)

# I need to store the result in my_string however I cannot figure out how to get this to work
my_string = highlight(something_here, MIME("text/html"), "a = 1+2", Lexers.JuliaLexer)

```

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [October 10, 2019, 2:07am UTC](https://discourse.julialang.org/t/printing-to-string-from-stream/29689/2 "2019-10-10T02:07:05Z")

</div>

Perhaps use `IOBuffer`

[https://docs.julialang.org/en/latest/base/io-network/#Base.IOBuffer](https://docs.julialang.org/en/latest/base/io-network/#Base.IOBuffer)

```julia
io = IOBuffer()
highlight(io, MIME("text/html"), "a = 1+2", Lexers.JuliaLexer)
my_string = String(take!(io))

```
