gpt4 book ai didi

haskell - 如何在 Haskell 中编写多行字符串?

转载 作者:行者123 更新时间:2023-12-02 14:01:52 25 4
gpt4 key购买 nike

假设我有这个带有换行符的字符串文字:

file :: String
file = "the first line\nthe second line\nthe third line"

有没有办法这样写?

file :: String
file = "the first line
the second line
the third line"

上面的尝试会导致此错误:

factor.hs:58:33:
lexical error in string/character literal at character '\n'
Failed, modules loaded: none.

最佳答案

你可以像这样编写多行字符串

x = "This is some text which we escape \
\ and unescape to keep writing"

打印为

"This is some text which we escape   and unescape to keep writing"

如果您希望将其打印为两行

x = "This is some text which we escape \n\
\ and unescape to keep writing"

打印为

This is some text which we escape
and unescape to keep writing

关于haskell - 如何在 Haskell 中编写多行字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22918837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com