Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

Strings and Codepoints

Strings are enclosed by double quotes ".

Simple String Literals

A plain string declared with double quotes such as "some string" can be assigned to fields of type String:

Internally, a plain string is an instance of the standard library feature const_string or codepoint. Both const_string and codepoint inherit from String. The static type of a string constant consisting of exactly one codepoint is codepoint otherwise it is String. You can see the difference when you compare the static type determined using type_of with the dynamic type returned by dynamic_type:

Consequently, a string constant can be assigned to a field of type String, but it cannot be assigned to a field of type const_string:

Escaped Characters

A plain string must not contain any of the characters $, {, }, " or \. To include one of these characters, it must be escaped by putting a backslash \ in front of it.

Also, a plain string must not contain any ASCII control characters in the range of 0x00..0x1f nor the DEL character (0x7f). In particular, a new line within a plain string is an error.

To include any of these forbidden characters or certain ASCII control characters, an escape sequence using a backslash \ can be used:

Escape sequence character ASCII code
\bBS0x08
\tHT0x09
\nLF0x0a
\fFF0x0c
\rCR0x0d
\sSP0x20
\"" 0x22
\$$ 0x24
\'' 0x27
\\\ 0x5c
\{{ 0x7b
\}} 0x7d
\0NUL0x00

Here is a small example using escaped control and special characters:

Converting instances to strings

All Fuzion features are heirs of Any, which provides a feature as_string to create an instance of String from any Fuzion instance. Any feature may redefine as_string to create a string representation appropriate for the specific feature.

The operator prefix $ is defined as a synonym for as_string, so a call $v is shorthand for v.as_string:

Embedded Expressions

Strings can be concatenated with the string representation of any instance using infix +:

Single identifiers or numeric literals can be embedded into a string literal using a $ immediately before the identifier as follows.

This embedding using $ does not work for expressions that consist of more than an identifier. For more complex expressions, you can use curly braces { and }:

This works even for code that spans several lines:

Arbitrary nesting of strings and expressions is also possible:

Multi-line Strings

Multi-line strings start and end with a fat quotation """. They mostly work just like 'normal' strings but have the following peculiarities.

  • A multi-line string is required to start in the first line following the fat quotation.
  • The first line of the multi-line string is the reference for the indentation to be used throughout the rest of the string. Thus all lines of the multi-line strings have to indented at least as much as the first line.
  • A multi-line string may use interpolation with $ and {} just like 'normal' strings.
  • Arbitrary nesting of multi-line strings is allowed.
  • Trailing white space in multi-line strings is disallowed.
  • For adding white space at the beginning of the first line or at the end of lines use escape codes described above.
  • Line terminators in multi-line strings are normalized to LF unless CR is explicitly included by using the escape code CR.

There are two special escape sequences in multi-line strings. A literal \ followed by a literal line feed or a literal carriage return cancels the newline. This is useful for splitting long strings over multiple lines in source code.

last changed: 2025-12-17
next: bool constants