问题在标题中。
如果我在 REPL 中执行此操作(Windows 命令行中的 SML/NJ)
val x = "hello\nworld";
我希望
val x = "hello
world" : string
或类似的东西,但我明白了
val x = "hello\nworld" : string
虽然我在某处发现\n 是 SML 字符串中的换行符。
最佳答案
显示字符串时,换行符显示为\n
.
但是,如果您尝试打印字符串,则会将其视为正确的换行符:
- val x = "hello\nworld";
> val x = "hello\nworld" : string
- print x;
hello
world> val it = () : unit
这只是字符串的显示方式,您不能让 SML 解释器将其显示为实际的换行符,除非您自己打印它。
关于string - 如何在字符串中添加换行符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26236180/