如何将字符串分成多行? [英] How do I break a string over multiple lines?
问题描述
在YAML中,我有一个很长的字符串.我想将其保留在编辑器的80列(或类似视图)内,所以我想破坏字符串.这是什么语法?
In YAML, I have a string that's very long. I want to keep this within the 80-column (or so) view of my editor, so I'd like to break the string. What's the syntax for this?
换句话说,我有这个:
Key: 'this is my very very very very very very long string'
我想拥有这个(或达到这种效果的东西):
and I'd like to have this (or something to this effect):
Key: 'this is my very very very ' +
'long string'
我想使用上面的引号,因此不需要在字符串中转义任何内容.
I'd like to use quotes as above, so I don't need to escape anything within the string.
推荐答案
使用yaml折叠样式,每个换行符都由一个空格代替.每行中的缩进将被忽略.一个换行符将插入到末尾.
Using yaml folded style, each line break is replaced by a space. The indention in each line will be ignored. A line break will be inserted at the end.
Key: >
This is a very long sentence
that spans several lines in the YAML
but which will be rendered as a string
with only a single carriage return appended to the end.
http://symfony.com/doc/current/components/yaml/yaml_format.html
您可以使用块记录指示器"消除尾随换行符,如下所示:
You can use the "block chomping indicator" to eliminate the trailing line break, as follows:
Key: >-
This is a very long sentence
that spans several lines in the YAML
but which will be rendered as a string
with NO carriage returns.
还有其他可用的控制工具(例如,用于控制缩进).
There are other control tools available as well (for controlling indentation for example).
请参见 https://yaml-multiline.info/
这篇关于如何将字符串分成多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!