如何在 YAML 中将字符串拆分为多行? [英] How do I break a string in YAML over multiple lines?

查看:24
本文介绍了如何在 YAML 中将字符串拆分为多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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. 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.

在任何一种情况下,每个换行符都被一个空格替换.

In either case, each line break is replaced by a space.

还有其他可用的控制工具(例如用于控制缩进).

There are other control tools available as well (for controlling indentation for example).

参见 https://yaml-multiline.info/

这篇关于如何在 YAML 中将字符串拆分为多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆