Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions docs/fsharp/language-reference/interpolated-strings.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}}"""
```
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Loading