Syntax

Builds a string from text and holes: each {expression} is replaced by Str(expression), and the whole string becomes a concatenation.

$"<text>{<expression>}<text>…"
{{
}}

Also written : $"

Parts

<text>Literal text, kept as written. {{ and }} give a literal brace.
<expression>Any expression that gives a number or a string, including a call: {Upper(name$)}. It cannot contain a string literal.

Good to know

  • The $ is mandatory and must touch the opening quote. A string without $ is left untouched, so JSON with braces stays data: "{\"size\":256}".
  • A hole ends at the first }. A " inside a hole ends the whole string, and the compiler reports an unclosed {. Put the text in a variable first.
  • An empty hole {} is refused ("Empty {} in interpolated string"), and so is an unclosed { ("Unclosed { in interpolated string"). A lone } outside a hole is kept as is.
  • There is no format part as in C#. {n:2} is not refused, but the program does not start. Round or pad inside the hole: {Str(n, 2)}.
  • An AS float variable shows every digit of its 32-bit value: 0.1 prints as 0.10000000149011612. Round it in the hole, as in the example.
  • AGK, DarkBASIC and PureBasic have no interpolation: they glue with + and Str(). The $"…" spelling is C#'s.

Example

name$ = "Ada"lives = 3speed AS float = 0.1Console($"{name$} has {lives} lives")      ' Ada has 3 livesConsole($"next life at {1250 + 750}")      ' next life at 2000Console($"{{braces}} and {Len(name$)}")    ' {braces} and 3Console($"speed {Str(speed, 2)}")          ' speed 0.10
In the manual : Shorthands

Commands that go with it