Search code examples
smlsmlnj

Translate \n new line from Char to String in SML/NJ


I am trying to convert #"\n", a Char, to "\n", a String. I used

Char.toString(#"\n");

and it gives

val it = "\\n" : string

Why does not it return "\n"?


Solution

  • Char.toString from the documentation.

    returns a printable string representation of the character, using, if necessary, SML escape sequences.

    It also specifies that some control characters are converted to two-character escape sequences and \n is one of it.

    To return a string of size one, use String.str.

    - String.str(#"\n");
    val it = "\n" : string