如何在 Zig 中声明多行字符串?

问题描述 投票:0回答:1

如何在 Zig 中编写跨多行的字符串?

例如:

var str = `hello
second line
world
fourth line
`
string multiline string-literals zig
1个回答
0
投票

Zig 具有这种奇怪但很酷的语法,其中包含以

\\
开头的多行以及下一行中的
;

这是一个单例:

const str =
    \\hello
    \\second line
    \\world
    \\fourth line
;

这是一个由 2 个多行字符串组成的数组:

const array_of_multiline_strings = [_][]const u8{
    \\hello
    \\world
    ,
    \\goodbye
    \\world
};
© www.soinside.com 2019 - 2024. All rights reserved.