Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write an inline big string in F#

In C# I can use:

string myBigString = @"

<someXmlForInstance>
  <someChild />
</someXmlForInstance>

";

How to do this in F#?

like image 831
knocte Avatar asked Aug 01 '12 10:08

knocte


People also ask

What is f {} in Python?

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.

How do I add strings to F?

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.

What is F in front of 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 {} .

How do I format a multi line string in Python?

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.


1 Answers

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>"""
like image 74
Joel Mueller Avatar answered Sep 21 '22 14:09

Joel Mueller