string - Ada 中的多行字符串文字

标签 string ada multiline literals

如何在 Ada 中创建一个包含换行符的字符串,其定义也包含这些换行符?

我试过在行尾使用 0..2 个反斜杠,但没有一个可以编译:

   usage_info : String := "\
This should be the first line
and both the definition and the output
should contain newlines.";

在 PHP 中这将是:

<<<BLOCK
1
2
3
BLOCK;

In C++ this would be:

const std::string s = "\
1
2
3";

In C#, it would be:

const string s =
@"1
2
3";

最佳答案

据我所知,Ada 和 Java 一样,不支持多行文字。 我唯一看到的是这样的:

usage_info : String := "This should be the first line" & CR & LF
                     & "and both the definition and the output" & CR & LF 
                     & "should contain newlines.";

当然,您需要with使用 Ada.Characters.Latin_1 来使这些常量可见。

关于string - Ada 中的多行字符串文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58517814/

相关文章:

gcc - 将 math.h 与 gprbuild 链接起来

generics - 有没有办法在 Ada(特别是 GNAT)中创建和重用方面集?

c - 如何获取 gcc 的 Ada 规范搜索路径

python - 为什么这个正则表达式在第一个捕获组再次出现之前不匹配所有内容?

Java 不等于字符串语法不起作用

json - flutter JSON解码未处理的异常: type 'Null' is not a subtype of type 'String'

java - 是否可以显示多个文本字段,供用户在每个文本字段中输入他们想要的项目数?

Groovy 中的多行正则表达式

python - 将文本文件中的数据的度分转换为弧度

Python 文档 ( :obj :`str` ) vs (str)