Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

String interpolation allows you to insert the value of almost any valid boo expression inside a string by quoting the expression with $().

The parentheses are unnecessary if the expression is just a variable:

String interpolation kicks in for both double and triple quoted strings:

You can scape the $ character to prevent interpolation:

You don't need to scape the $ char when it is not followed by the ( character:

Interpolation doesn't kick in inside single quoted strings:

String Formatting

Boo also has the "%" (modulus) operator as shorthand for .NET/Mono's string.Format method. This is a little more similar to Python's string interpolation, too.

Combine boo and .net's string formatting

This tip suggested by Arron Washington. You can combine the two above techniques to get the best of both, like in this example:

Another way is to pass formatting codes to the ToString method:

See Also

Here are some related resources on .NET string formatting:

  • No labels