Skip to content

Commit 2d8e549

Browse files
authored
Document verbatim interpolated strings using $@ and @$ syntax in F# (#48861)
1 parent d19e83b commit 2d8e549

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

docs/fsharp/language-reference/interpolated-strings.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Interpolated strings
33
description: Learn about interpolated strings, a special form of string that allows you to embed F# expressions directly inside them.
4-
ms.date: 11/12/2020
4+
ms.date: 10/01/2025
55
---
66

77
# Interpolated strings
@@ -13,6 +13,8 @@ Interpolated strings are [strings](strings.md) that allow you to embed F# expres
1313
```fsharp
1414
$"string-text {expr}"
1515
$"string-text %format-specifier{expr}"
16+
$@"string-text {expr}"
17+
@$"string-text {expr}"
1618
$"""string-text {"embedded string literal"}"""
1719
$$"""string-text %%format-specifier{{expr}}"""
1820
```
@@ -56,7 +58,29 @@ In the previous example, the code mistakenly passes the `age` value where `name`
5658

5759
## Verbatim interpolated strings
5860

59-
F# supports verbatim interpolated strings with triple quotes so that you can embed string literals.
61+
F# supports verbatim interpolated strings in two ways:
62+
63+
### Using `$@` or `@$` prefix
64+
65+
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.
66+
67+
```fsharp
68+
let name = "Alice"
69+
let path = @"C:\Users\Alice\Documents"
70+
71+
// Using $@ prefix
72+
printfn $@"User {name} has files in: {path}"
73+
74+
// Using @$ prefix (also valid)
75+
printfn @$"User {name} has files in: {path}"
76+
77+
// Embedding quotes - use "" to represent a single "
78+
let message = $@"He said ""{name}"" is here"
79+
```
80+
81+
### Using triple quotes
82+
83+
F# also supports verbatim interpolated strings with triple quotes so that you can embed string literals without escaping.
6084

6185
```fsharp
6286
let age = 30
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Verbatim interpolated strings with $@ or @$
2+
let name = "Alice"
3+
let path = @"C:\Users\Alice\Documents"
4+
5+
// Using $@ prefix (interpolated verbatim string)
6+
printfn $@"User {name} has files in: {path}"
7+
8+
// Using @$ prefix (also valid)
9+
printfn @$"User {name} has files in: {path}"
10+
11+
// Embedding quotes without escaping
12+
let message = $@"He said ""{name}"" is here"
13+
printfn "%s" message
14+
15+
// Multi-line verbatim interpolated strings
16+
let multiline = $@"Name: {name}
17+
Path: {path}
18+
Status: Active"
19+
printfn "%s" multiline

0 commit comments

Comments
 (0)