From 95053ce009108886d83bc0ae3d86138d93964bcc Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Thu, 9 Jun 2022 10:43:03 -0400 Subject: [PATCH 1/9] Add initial basic text to string guide --- docs/csharp/programming-guide/strings/index.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/csharp/programming-guide/strings/index.md b/docs/csharp/programming-guide/strings/index.md index 8eab568e6d3dd..3809f87c77a85 100644 --- a/docs/csharp/programming-guide/strings/index.md +++ b/docs/csharp/programming-guide/strings/index.md @@ -117,6 +117,12 @@ Beginning with C# 11, you can combine *raw string literals* with string interpol :::code language="csharp" source="./snippets/StringInterpolation.cs" id="InterpolationExample"::: +### Verbatim String Interpolation + +C# also allows verbatim string interpolation, for example across multiple lines, using the `$@` or `@$` operator. + +:::code language="csharp" source="./snippets/VerbatimStringInterpolation.cs" id="VerbatimInterpolationExample"::: + ### Composite formatting The utilizes placeholders in braces to create a format string. This example results in similar output to the string interpolation method used above. From 3772d6127abd5c59f39797758e8190b0c19f6f3a Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Thu, 9 Jun 2022 10:48:26 -0400 Subject: [PATCH 2/9] Change word for correctness --- docs/csharp/programming-guide/strings/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/programming-guide/strings/index.md b/docs/csharp/programming-guide/strings/index.md index 3809f87c77a85..10fc55aac2ef9 100644 --- a/docs/csharp/programming-guide/strings/index.md +++ b/docs/csharp/programming-guide/strings/index.md @@ -119,7 +119,7 @@ Beginning with C# 11, you can combine *raw string literals* with string interpol ### Verbatim String Interpolation -C# also allows verbatim string interpolation, for example across multiple lines, using the `$@` or `@$` operator. +C# also allows verbatim string interpolation, for example across multiple lines, using the `$@` or `@$` syntax. :::code language="csharp" source="./snippets/VerbatimStringInterpolation.cs" id="VerbatimInterpolationExample"::: From dfa27d862d8b542f6596ef8bb8f98ecfc46a651d Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Thu, 9 Jun 2022 10:52:20 -0400 Subject: [PATCH 3/9] Borrow language from the string interpolation guide --- docs/csharp/programming-guide/strings/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/csharp/programming-guide/strings/index.md b/docs/csharp/programming-guide/strings/index.md index 10fc55aac2ef9..dd35ca9bf5ecc 100644 --- a/docs/csharp/programming-guide/strings/index.md +++ b/docs/csharp/programming-guide/strings/index.md @@ -121,6 +121,8 @@ Beginning with C# 11, you can combine *raw string literals* with string interpol C# also allows verbatim string interpolation, for example across multiple lines, using the `$@` or `@$` syntax. +To interpret escape sequences literally, use a [verbatim](../../language-reference/tokens/verbatim.md) string literal. An interpolated verbatim string starts with the `$` character followed by the `@` character. Starting with C# 8.0, you can use the `$` and `@` tokens in any order: both `$@"..."` and `@$"..."` are valid interpolated verbatim strings. + :::code language="csharp" source="./snippets/VerbatimStringInterpolation.cs" id="VerbatimInterpolationExample"::: ### Composite formatting From dae056680e62223c141bff5036a01a443ccd1aa5 Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Thu, 9 Jun 2022 10:55:15 -0400 Subject: [PATCH 4/9] Add verbatim string interpolation example --- .../snippets/VerbatimStringInterpolation.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs diff --git a/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs b/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs new file mode 100644 index 0000000000000..4b106196b7514 --- /dev/null +++ b/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs @@ -0,0 +1,24 @@ +using System; + +namespace StringExamples; +public static class Interpolation +{ + public static void VerbatimInterpolationExamples() + { + // + var jh = (firstName: "Jupiter", lastName: "Hammon", born: 1711, published: 1761); + Console.WriteLine($@"{jh.firstName} {jh.lastName} + was an African American poet born in {jh.born}."); + Console.WriteLine(@$"He was first published in {jh.published} + at the age of {jh.published - jh.born}."); + + // Output: + // Jupiter Hammon + // was an African American poet born in 1711. + // He was first published in 1761 + // at the age of 50. + // + + System.Console.WriteLine(); + } +} From b699f6627a915f382ef9d8bbb254e4be3c456f87 Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Thu, 9 Jun 2022 10:56:48 -0400 Subject: [PATCH 5/9] De-pluralize examples since theres' only 1 --- .../strings/snippets/VerbatimStringInterpolation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs b/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs index 4b106196b7514..4f5b8d120fec9 100644 --- a/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs +++ b/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs @@ -3,7 +3,7 @@ namespace StringExamples; public static class Interpolation { - public static void VerbatimInterpolationExamples() + public static void VerbatimInterpolationExample() { // var jh = (firstName: "Jupiter", lastName: "Hammon", born: 1711, published: 1761); From b054b3b6f282390ae1acc268e3ab93f375c2410b Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Thu, 9 Jun 2022 10:57:44 -0400 Subject: [PATCH 6/9] give class a unique name --- .../strings/snippets/VerbatimStringInterpolation.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs b/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs index 4f5b8d120fec9..565703b3b7519 100644 --- a/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs +++ b/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs @@ -1,7 +1,7 @@ using System; namespace StringExamples; -public static class Interpolation +public static class VerbatimInterpolation { public static void VerbatimInterpolationExample() { @@ -18,7 +18,5 @@ public static void VerbatimInterpolationExample() // He was first published in 1761 // at the age of 50. // - - System.Console.WriteLine(); } } From 18b4729e224bc1e6175ef55b91695105b5167967 Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Thu, 9 Jun 2022 10:58:29 -0400 Subject: [PATCH 7/9] update ID for sample --- .../strings/snippets/VerbatimStringInterpolation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs b/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs index 565703b3b7519..48a1b23a81fc4 100644 --- a/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs +++ b/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs @@ -5,7 +5,7 @@ public static class VerbatimInterpolation { public static void VerbatimInterpolationExample() { - // + // var jh = (firstName: "Jupiter", lastName: "Hammon", born: 1711, published: 1761); Console.WriteLine($@"{jh.firstName} {jh.lastName} was an African American poet born in {jh.born}."); @@ -17,6 +17,6 @@ public static void VerbatimInterpolationExample() // was an African American poet born in 1711. // He was first published in 1761 // at the age of 50. - // + // } } From 53a41d3211fa0c072b826fcc647e828ebcf2f8e9 Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Thu, 9 Jun 2022 11:07:14 -0400 Subject: [PATCH 8/9] Update docs/csharp/programming-guide/strings/index.md Thanks Bill! Co-authored-by: Bill Wagner --- docs/csharp/programming-guide/strings/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/programming-guide/strings/index.md b/docs/csharp/programming-guide/strings/index.md index dd35ca9bf5ecc..d9391719e2f4e 100644 --- a/docs/csharp/programming-guide/strings/index.md +++ b/docs/csharp/programming-guide/strings/index.md @@ -123,7 +123,7 @@ C# also allows verbatim string interpolation, for example across multiple lines, To interpret escape sequences literally, use a [verbatim](../../language-reference/tokens/verbatim.md) string literal. An interpolated verbatim string starts with the `$` character followed by the `@` character. Starting with C# 8.0, you can use the `$` and `@` tokens in any order: both `$@"..."` and `@$"..."` are valid interpolated verbatim strings. -:::code language="csharp" source="./snippets/VerbatimStringInterpolation.cs" id="VerbatimInterpolationExample"::: +:::code language="csharp" source="./snippets/VerbatimStringInterpolation.cs" id="VerbatimStringInterpolation"::: ### Composite formatting From 6a4f091272e965824425c788ab2b4897b0d22593 Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Thu, 9 Jun 2022 11:30:09 -0400 Subject: [PATCH 9/9] Update docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs This makes the most sense to me. Co-authored-by: Bill Wagner --- .../strings/snippets/VerbatimStringInterpolation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs b/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs index 48a1b23a81fc4..d7b7a37a5373c 100644 --- a/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs +++ b/docs/csharp/programming-guide/strings/snippets/VerbatimStringInterpolation.cs @@ -14,9 +14,9 @@ public static void VerbatimInterpolationExample() // Output: // Jupiter Hammon - // was an African American poet born in 1711. + // was an African American poet born in 1711. // He was first published in 1761 - // at the age of 50. + // at the age of 50. // } }