在C#中我可以使用:
string myBigString = @"
<someXmlForInstance>
<someChild />
</someXmlForInstance>
";
如何在 F# 中实现这个功能?
在 F# 3.0,VS 2012 中,支持 三引号字符串。
三引号字符串中,三引号之间的所有内容("""...""")都会被保留字面量;没有转义。因此,如果我想要将 XAML 作为字符串字面量,那很容易:
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>"""
尝试一下:
let str1 = "abc
def"
let str2 = "abc\
def"
更多信息,请参见: http://msdn.microsoft.com/zh-cn/library/362314fe.aspx