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

String constants

Strings are enclosed by double quotes ".

Simple Strings

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

Internally, such plain string is an instance of the standard library feature conststring, which inherits from string. However, its static type is string, so it cannot be assigned to a field of type conststring:

Escaped Charactters

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 fobidden characters or certain ASCII control characters, an escape sequence using a backslach \ can be used:

Escape sequence character ASCII code
\"" 0x22
\$$ 0x24
\'' 0x27
\\\ 0x5c
\{{ 0x7b
\}} 0x7d

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

Converting instances to strings

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

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

Embedded Expressions

String 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 consit of more than a single identifier. For more complex expressions, you can use curly braces { and }:

This works even for more complex code that extends over several lines:

And it is even possible to use strings with nesting in an expression nested in a string:

Multi-line Strings

There is currently no specific support for multi line strings. Concatenation of several single line strings can help as a workaround. Note that the overall string has to be wrapped in parentheses since the expression would otherwise be limited to one line.