Char.toString 没有特殊处理 " 和 \

Char.toString without special handling of " and \

我正在尝试将字符转换为字符串,如下所示:

Char.toString(#"x")

对于大多数字符,这是有效的,但是对于 "\,在它之前添加一个额外的 \

- Char.toString(#"\"");
val it = "\\"" : string

这对我来说是不受欢迎的行为。我希望上面的代码片段return val it = "\"" : string。 SML 中是否有任何内置函数可以执行此操作?

来自the documentation of Char.toString

returns a printable string representation of the character, using, if necessary, SML escape sequences. Printable characters, except for #"\" and #"\"", are left unchanged. Backslash #"\" becomes "\"; double quote #"\"" becomes "\"". [...]

To convert a character to a length-one string containing the character, use the function String.str.

并且来自 String.str 的文档:

str c is the string of size one containing the character c.

所以 str #"\"" 会完全按照您的意愿去做。