5 ms·
I got confused at the first example. var xml = """ <element attr="content"> <body> </body> </el
by crispyambulance 5y ago
I got confused at the first example.
var xml = """
<element attr="content">
<body>
</body>
</element>
""";
And then they say that xml gets this...
<element attr="content">
<body>
</body>
</element>
But they don't explicitly say if the new lines after and before the """ 's are considered part of the literal string or not.
Are they?
- laurensr 5y agoIn Java the leading [1] newlines are stripped as well as the trailing ones [2]. [1]: https://cr.openjdk.java.net/~jlaskey/Strings/TextBlocksGuide_v11.html#:~:text=all%20of%20the%20indentation%20is%20treated%20as%20incidental https://cr.openjdk.java.net/~jlaskey/Strings/TextBlocksGuide... [2]: https://cr.openjdk.java.net/~jlaskey/Strings/TextBlocksGuide_v11.html#:~:text=red%0A%20%20%20%20green%0A%20%20%20%20blue-,Trailing%20White%20Space,-Trailing%20white%20space https://cr.openjdk.java.net/~jlaskey/Strings/TextBlocksGuide...
- rawling 5y agoNo, although you're right, it doesn't look like they make it clear (although the example is in a little code element which presumably doesn't have leading or trailing newlines). Later on, > In the case of multi_line_raw_string_literal the initial whitespace* new_line and the final new_line whitespace* is not part of the value of the string.
- sbelskie 5y agoThe construct seems to be defined as: ``` multi_line_raw_string_literal : raw_string_literal_delimiter whitespace* new_line (raw_content | new_line)* new_line whitespace* raw_string_literal_delimiter ; ``` Which I think says that the opening and closing new lines (after and before the """'s) are NOT part of the content of the string literal, but new lines between them can be part of the string literal.
- Metasyntactic 5y agoHi. I'm the designer of this lang feature. The specification covers this. However, to be clear, neither new line after the first `"""` is not part of the literal, nor is the newline before the last `"""`. Thanks!
- hackerfromthefu 5y agoAs someone who has used C# since V1 beta, I would like to recommend slow down on the new features. They are adding weight to the tree and eventually it will fall over, or C# will become like C++ with too much complexity that limits usability and use. Another comment here suggested just make a trivial way to reference an embedded text file resource, and that is already very possible and not hard already, as well as use of string Resources.
- crispyambulance 5y agoThanks, this is a nice feature!