# (raw) string literal linebreaks on Windows

**URL:** <https://discourse.julialang.org/t/raw-string-literal-linebreaks-on-windows/14895>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 13, 2018, 5:38am UTC](https://discourse.julialang.org/t/raw-string-literal-linebreaks-on-windows/14895 "2018-09-13T05:38:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 13, 2018, 5:38am UTC](https://discourse.julialang.org/t/raw-string-literal-linebreaks-on-windows/14895/1 "2018-09-13T05:38:20Z")

</div>

This came up in unit tests: if I have a line break in a string literal, is the result platform-dependent? Eg on Linux,

```julia
julia> raw"1
       2"
"1\n2"

julia> """
       1
       2
       """
"1\n2\n"

```

but I wonder if this would give me `"\r\n"` linebreaks on Windows. Can someone with a Windows machine please check this?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 13, 2018, 6:27am UTC](https://discourse.julialang.org/t/raw-string-literal-linebreaks-on-windows/14895/2 "2018-09-13T06:27:17Z")

</div>

```julia
julia> Base.Sys.KERNEL
:NT

julia> raw"1
       2"
"1\n2"

julia> """
       1
       2
       """
"1\n2\n"

```

Doesn’t look like it.

I wonder if this is intended - writing e.g. log files on windows would potentially need special handling for newline characters, as `println` behaves the same.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 13, 2018, 6:36am UTC](https://discourse.julialang.org/t/raw-string-literal-linebreaks-on-windows/14895/3 "2018-09-13T06:36:05Z")

</div>

Thanks. Can you please check the same with `println`? Eg

```julia
julia> let io = IOBuffer()
       println(io, "foo")
       String(take!(io))
       end
"foo\n"

```

on Linux. But perhaps this outputs `\r\n` linebreaks on Windows?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 13, 2018, 6:38am UTC](https://discourse.julialang.org/t/raw-string-literal-linebreaks-on-windows/14895/4 "2018-09-13T06:38:08Z")

</div>

It behaves the same. I noticed that behaviour a while back while writing a small tool which also logs stuff (the logs ended up not being used, ironically - but at least the capability is there).

```julia
julia> let io = IOBuffer()
              println(io, "foo")
                     String(take!(io))
                            end
"foo\n"

```

I guess it comes down to whether Base or each individual developer should make the decision on how to print this based on the platform. There’s good arguments either way. Personally, I lean more towards one single implementation to avoid as many differences between platforms as possible. Although I do like the concept of a true carriage return (EDIT: after some testing, carriage return works on either platform anyway).

EDIT: Well, there’s the culprit:

> <https://github.com/JuliaLang/julia/blob/b4c370dd05ac33d0c8c02b440b861e8582d1fc74/base/coreio.jl#L5>

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 13, 2018, 6:45am UTC](https://discourse.julialang.org/t/raw-string-literal-linebreaks-on-windows/14895/5 "2018-09-13T06:45:49Z")

</div>

I have not formed an opinion on whether this is the desired way, I was just asking because I am curious how newlines are meant to be handled cross-platform.

Does the `\n` not cause a problem on Windows when using the terminal? Or is it somehow converted?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 13, 2018, 6:48am UTC](https://discourse.julialang.org/t/raw-string-literal-linebreaks-on-windows/14895/6 "2018-09-13T06:48:01Z")

</div>

Seems to work just fine from a CMD.exe:

```julia
C:\Users\<snip>>julia -e println(\"test\ntest\")
test
test

```

I do seem to recall some change to ConsoleHost a while back where support for this was added - since WSL (Windos Subsystem for Linux, the Linux shell thing on Windows) came into existence, they’ve added a bunch of Unix support to Windows. Some programs like Notepad are still lagging behind a bit, but even they are [getting updated](https://blogs.msdn.microsoft.com/commandline/2018/05/08/extended-eol-in-notepad/) with, I think, the coming september update.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 13, 2018, 6:55am UTC](https://discourse.julialang.org/t/raw-string-literal-linebreaks-on-windows/14895/7 "2018-09-13T06:55:31Z")

</div>

There’s also the possibility for this to mess up on Mac (if I remember correctly, just `\r` is used over there). I can’t test that though.

EDIT: Apparently, that’s just a legacy thing.
