How to add line break to string?

The question is in the title.

If I do this in REPL (SML / NJ on the Windows command line)

val x = "hello\nworld";

I would expect

val x = "hello
world" : string

or something like that, but I get

val x = "hello\nworld" : string

although I found somewhere that \ n is a line break in SML lines.

+4
source share
1 answer

When a line is displayed, a line break is displayed as \n.

However, if you try to print a line, you will see it as the correct line break:

- val x = "hello\nworld";
> val x = "hello\nworld" : string
- print x;
hello
world> val it = () : unit

It's just how a string is displayed, and you cannot force the SML interpreter to display it as an actual new string, except by printing it yourself.

+6
source

All Articles