【问题标题】:how do I add a line break in a string?如何在字符串中添加换行符?
【发布时间】:2014-12-01 21:22:06
【问题描述】:

问题在标题中。

如果我在 REPL 中执行此操作(Windows 命令行中的 SML/NJ)

val x = "hello\nworld";

我希望

val x = "hello
world" : string

或类似的东西,但我明白了

val x = "hello\nworld" : string

虽然我在某处发现 \n 是 SML 字符串中的换行符。

【问题讨论】:

  • val x = "hello\\nworld"; 怎么样?

标签: string line-breaks sml read-eval-print-loop


【解决方案1】:

显示字符串时,换行显示为\n

但是,如果您尝试打印字符串,您会看到它是正确的换行符:

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

这只是字符串的显示方式,您不能让 SML 解释器将其显示为实际的换行符,除非您自己打印它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-14
    • 2016-07-19
    • 2023-03-30
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    相关资源
    最近更新 更多