string 方案中的换行符(球拍)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15423969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Newline in Scheme (Racket)
提问by Asqan
It is possible to have a new line when you write with "display" like
当您使用“显示”编写时,可能会有一个新行,例如
(display "exa \n mple")
But the problem is that there is no any code to have a new line in strings? Like:
但问题是没有任何代码可以在字符串中换行吗?喜欢:
"exa \n mple"
Expected ->
预期 ->
exa
mple
What I have:
我拥有的:
exa \n mple
I couldn't find any information in racket-documentation or anywhere else.
我在球拍文档或其他任何地方都找不到任何信息。
回答by rafcolm_
Something like:
就像是:
(display "line\nhola")
should do it.
应该这样做。
No idea why you would need whatever was posted above.
不知道为什么您需要上面发布的任何内容。
回答by óscar López
If you need a way to add a newline between strings, then this will work:
如果您需要一种在字符串之间添加换行符的方法,那么这将起作用:
(define s (string-append "exa " "\n" " mple"))
s
=> "exa \n mple"
(display s)
=> exa
mple
In the above snippet, I'm using string-append
for sticking together two strings with a newline in the middle. The resulting string s
will have a newline in-between when you use it, for example by displaying it.
在上面的代码段中,我string-append
用于将两个字符串粘在一起,中间有一个换行符。s
当您使用它时,生成的字符串中间会有一个换行符,例如通过显示它。
Obviously it will show up as "exa \n mple"
, you can't expect the string to jump from one line to the other unlessyou display it, print it, show it, write it, etc.
显然它会显示为"exa \n mple"
,你不能指望字符串从一行跳到另一行,除非你显示它,打印它,显示它,写它等等。