How do you write multiline strings in Go?

前端 未结 9 933
傲寒
傲寒 2020-12-07 07:25

Does Go have anything similar to Python\'s multiline strings:

\"\"\"line 1
line 2
line 3\"\"\"

9条回答
  •  暖寄归人
    2020-12-07 07:49

    From String literals:

    • raw string literal supports multiline (but escaped characters aren't interpreted)
    • interpreted string literal interpret escaped characters, like '\n'.

    But, if your multi-line string has to include a backquote (`), then you will have to use an interpreted string literal:

    `line one
      line two ` +
    "`" + `line three
    line four`
    

    You cannot directly put a backquote (`) in a raw string literal (``xx\).
    You have to use (as explained in "how to put a backquote in a backquoted string?"):

     + "`" + ...
    

提交回复
热议问题