0

我正在尝试将字符串写入文件,但每次我这样做时都会有引号。

我试过了

(call-with-output-file file-path
  (lambda(output-port)(write "some text" output-port)))

(let ((p (open-output-file file-path)))
      (write "some text" p)
      (close-output-port p))

但在这两种情况下,我都预料到"some text"但得到了"\"some text\""

我目前正在从事鸡肉计划,但我认为这并不重要。

4

1 回答 1

4

write用于将 S 表达式序列化到文件中。它与 相反read,它将序列化的 S 表达式读回列表、符号、字符串等。这意味着write将像在源代码中一样输出所有内容。

如果您只想将字符串输出到端口,请使用display

(call-with-output-file file-path
  (lambda(output-port)
    (display "some text" output-port)))

或者在 CHICKEN 中,您可以使用printfor fprintf

(call-with-output-file file-path
  (lambda(output-port)
    (fprintf output-port 
             "Printing as s-expression: ~S, as plain string: ~A"
             "some text"
             "some other test")))

这会将以下内容打印到文件中:

Printing as s-expression: "some text", as plain string: some other text
于 2015-12-10T20:26:45.707 回答