Triple-Quoted Strings in F# 3.0

F# supports 3 different types of strings which includes Normal , Verbatim ( @ ) and Triple-Quoted Strings . The first two are similar to what is available in C# . so what is this Triple-Quoted String all about in F# ?

What are Triple-Quoted Strings in F# 3.0 ?

Assume a scenario where you need to display a string that includes double quotes for example . We might have to implement it by escaping the characters . For example , take the example of a string developerpublish is a Programming and “Mobile” Development website. In c# , we have to escape the characters to display double quotes before and after Mobile. Below is a sample code in C#.

public void Display()
{
   string WindowsPhoneTutorials = "developerpublish is a Programming and "Mobile" Development website";
}

How to avoid using escape characters in this case ? . In F# , the triple-quoted string can be used to achieve this . What ever is in between the triple quotes is generally kept in verbatim . It can generally be used whereever we have to avoid escape characters like you have a XAML tag generated in code behind with properties etc.

 

open System
[<EntryPoint>]
let main argv =
    let stringOS = """"developerpublish" is a Programming Blog on Mobile Development"""
    Console.WriteLine(stringOS)
    let retval = Console.ReadLine()
    0

image

Leave a Reply