From 53f06f1fc34cbed763af148cdbb1fc29b41ad0dc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 1 Oct 2025 13:12:25 +0000 Subject: [PATCH 1/2] Initial plan From 5f7abde634113678e8c80a8512fc6b4053754c5a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 1 Oct 2025 13:26:20 +0000 Subject: [PATCH 2/2] Document verbatim interpolated strings using $@ and @$ syntax Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- .../interpolated-strings.md | 28 +++++++++++++++++-- .../interpolated-strings/verbatim.fsx | 19 +++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 docs/fsharp/language-reference/snippets/interpolated-strings/verbatim.fsx diff --git a/docs/fsharp/language-reference/interpolated-strings.md b/docs/fsharp/language-reference/interpolated-strings.md index 26f9f1e68933c..e9aeed973853d 100644 --- a/docs/fsharp/language-reference/interpolated-strings.md +++ b/docs/fsharp/language-reference/interpolated-strings.md @@ -1,7 +1,7 @@ --- title: Interpolated strings description: Learn about interpolated strings, a special form of string that allows you to embed F# expressions directly inside them. -ms.date: 11/12/2020 +ms.date: 10/01/2025 --- # Interpolated strings @@ -13,6 +13,8 @@ Interpolated strings are [strings](strings.md) that allow you to embed F# expres ```fsharp $"string-text {expr}" $"string-text %format-specifier{expr}" +$@"string-text {expr}" +@$"string-text {expr}" $"""string-text {"embedded string literal"}""" $$"""string-text %%format-specifier{{expr}}""" ``` @@ -56,7 +58,29 @@ In the previous example, the code mistakenly passes the `age` value where `name` ## Verbatim interpolated strings -F# supports verbatim interpolated strings with triple quotes so that you can embed string literals. +F# supports verbatim interpolated strings in two ways: + +### Using `$@` or `@$` prefix + +You can combine the interpolation prefix `$` with the verbatim string prefix `@` in any order. Verbatim strings ignore escape sequences (except for `""` to represent a quotation mark) and can span multiple lines. This is especially useful when working with file paths or strings containing backslashes and quotes. + +```fsharp +let name = "Alice" +let path = @"C:\Users\Alice\Documents" + +// Using $@ prefix +printfn $@"User {name} has files in: {path}" + +// Using @$ prefix (also valid) +printfn @$"User {name} has files in: {path}" + +// Embedding quotes - use "" to represent a single " +let message = $@"He said ""{name}"" is here" +``` + +### Using triple quotes + +F# also supports verbatim interpolated strings with triple quotes so that you can embed string literals without escaping. ```fsharp let age = 30 diff --git a/docs/fsharp/language-reference/snippets/interpolated-strings/verbatim.fsx b/docs/fsharp/language-reference/snippets/interpolated-strings/verbatim.fsx new file mode 100644 index 0000000000000..52db7c8163ebb --- /dev/null +++ b/docs/fsharp/language-reference/snippets/interpolated-strings/verbatim.fsx @@ -0,0 +1,19 @@ +// Verbatim interpolated strings with $@ or @$ +let name = "Alice" +let path = @"C:\Users\Alice\Documents" + +// Using $@ prefix (interpolated verbatim string) +printfn $@"User {name} has files in: {path}" + +// Using @$ prefix (also valid) +printfn @$"User {name} has files in: {path}" + +// Embedding quotes without escaping +let message = $@"He said ""{name}"" is here" +printfn "%s" message + +// Multi-line verbatim interpolated strings +let multiline = $@"Name: {name} +Path: {path} +Status: Active" +printfn "%s" multiline