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

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn about the error message “FileOpenAccessDenied – You do not have permissions to open this file...
  • .NET
  • December 3, 2024
You might have had a situation where your code once worked fine in ASP.NET application but now throws the below...
  • .NET
  • December 3, 2024
C# uses the flower bracket “{” and “}” to identify the block or scope of the function or program ....
  • .NET
  • December 3, 2024