Fsharp: Single Quoted String

By Xah Lee. Date: .

Single Quoted String

String can be quoted by QUOTATION MARK. E.g. "abc"

// string
let xx = "aa bb"
printfn "%s" xx
// aa bb
// string with literal newline
let xx = "aa
bb"
printfn "%s" xx
(*
aa
bb
*)

String with escape sequence

Inside quotation marks, backslash has special meaning, known as Escape Sequence. e.g. \n means a newline.

// string with escape sequence
let xx = "line 1\nline 2"
printfn "%s" xx
(*
line 1
line 2
 *)
// string with embeded QUOTATION MARK
let xx = "he said \"that\"."
printfn "%s" xx
// he said "that".

Backslash at end of line

Backslash at end of line has special meaning. It joins next line and removes any white space in beginning of next line.

// backslash at end of line means join lines
let xx = "aa\
   bb"
printfn "%s" xx
// aabb

Fsharp, String