# Overriding Base.show with multi-line string returns literal "\\n"

**URL:** <https://discourse.julialang.org/t/overriding-base-show-with-multi-line-string-returns-literal-n/80500>\
**Category:** New to Julia\
**Tags:** strings, show\
**Created:** [May 4, 2022, 7:15pm UTC](https://discourse.julialang.org/t/overriding-base-show-with-multi-line-string-returns-literal-n/80500 "2022-05-04T19:15:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![FireCrumb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/firecrumb/32/35370_2.png) [@FireCrumb](https://discourse.julialang.org/u/FireCrumb)\
**Post date:** [May 4, 2022, 7:15pm UTC](https://discourse.julialang.org/t/overriding-base-show-with-multi-line-string-returns-literal-n/80500/1 "2022-05-04T19:15:04Z")

</div>

Hi,  
I have a composite struct `ABC` with various fields `A`,`B`,`C`, which I want to display in a clear way on the screen (and later in Jupyter, but starting with REPL/console).

Here’s my code:

```julia
struct ABC
    A::Vector{Int64}
    B::Vector{Float32}
    C::Vector{String}
end

abc = ABC(
    [1,2,3],
    [4.5, 6.7, 8.9],
    ["hello", "world"]
)

function Base.show(io::IO, x::ABC)
    show(io,
    """
    A:
        $(x.A)
    
    B:
        $(x.B)

    C:
        $(x.C)
    """)
end

println(abc)

```

However, it shows a string with “\n” rather than actual newlines:

```julia
"A:\n [1, 2, 3]\n\nB:\n Float32[4.5, 6.7, 8.9]\n\nC:\n [\"hello\", \"world\"]\n"

```

What am I missing?

Note: also tried [PrettyPrint.jl](https://github.com/thautwarm/PrettyPrint.jl) and [PrettyPrinting.jl](https://github.com/MechanicalRabbit/PrettyPrinting.jl) but they seem to return similar output to `print` for this case.

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [May 4, 2022, 7:20pm UTC](https://discourse.julialang.org/t/overriding-base-show-with-multi-line-string-returns-literal-n/80500/2 "2022-05-04T19:20:58Z")

</div>

Inside your `Base.show` implementation, you want to call `print`, not `show` on the string. `show` will always give you some output that you can ideally copy-and-paste into the REPL and get back the same object. `print` is for when you want to just print the string as-is, but it falls back to `show` for most other objects.
