# Way to get string representation of an Expression?

**URL:** <https://discourse.julialang.org/t/way-to-get-string-representation-of-an-expression/7778>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 15, 2017, 5:10am UTC](https://discourse.julialang.org/t/way-to-get-string-representation-of-an-expression/7778 "2017-12-15T05:10:04Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Post date:** [September 4, 2021, 2:04pm UTC](https://discourse.julialang.org/t/way-to-get-string-representation-of-an-expression/7778/7 "2021-09-04T14:04:55Z")

</div>

As I found somewhere on them internets, you can use `Base.show_unquoted` to convert any `Expr` to a string of valid Julia code:

```julia
julia> Base.show_unquoted(stdout, :(import Woof; import Bowow))
begin
    import Woof
    #= REPL[5]:1 =#
    import Bowow
end

```

To convert to a string, use `IOBuffer`, or write to a file:

```julia
julia> buf = IOBuffer();

julia> Base.show_unquoted(buf, :(import Woof; import Bowow))

julia> String(take!(buf))
"begin\n import Woof\n #= REPL[11]:1 =#\n import Bowow\nend"

```

---

_[View the full topic](https://discourse.julialang.org/t/way-to-get-string-representation-of-an-expression/7778)._
