In C# I can use:
string myBigString = @"
<someXmlForInstance>
<someChild />
</someXmlForInstance>
";
How to do this in F#?
The f or F in front of strings tells Python to look at the values inside {} and substitute them with the values of the variables if exist.
Strings in Python are usually enclosed within double quotes ( "" ) or single quotes ( '' ). To create f-strings, you only need to add an f or an F before the opening quotes of your string. For example, "This" is a string whereas f"This" is an f-String.
The f means Formatted string literals and it's new in Python 3.6 . A formatted string literal or f-string is a string literal that is prefixed with 'f' or 'F' . These strings may contain replacement fields, which are expressions delimited by curly braces {} .
In Python, you have different ways to specify a multiline string. You can have a string split across multiple lines by enclosing it in triple quotes. Alternatively, brackets can also be used to spread a string into different lines. Moreover, backslash works as a line continuation character in Python.
In F# 3.0, VS 2012, support was added for triple-quoted strings.
In a triple-quoted string, everything between triple-quotes ("""...""") is kept verbatim; there is no escaping at all. As a result, if I want to have a bit of XAML as a string literal, it’s easy:
let xaml = """
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="mainPanel">
<Border BorderThickness="15.0" BorderBrush="Black">
<StackPanel Name="stackPanel1">
<TextBlock Text="Super BreakAway!" FontSize="24" HorizontalAlignment="Center" />
<TextBlock Text="written in F#, by Brian McNamara - press 'p' to pause"
FontSize="12" HorizontalAlignment="Center" />
<Border BorderThickness="2.0" BorderBrush="Black">
<Canvas Name="canvas" Background="White" />
</Border>
</StackPanel>
</Border>
</StackPanel>"""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With