Fsharp: String

By Xah Lee. Date: . Last updated: .

What is String

Single Quoted String

// single quote string
let xx = "aa bb"
printfn "%s" xx
// aa bb
// single quote string with literal newline
let xx = "aa
bb"
printfn "%s" xx
(*
aa
bb
*)
// single quote string with escape sequence
let xx = "line 1\nline 2"
printfn "%s" xx
(*
line 1
line 2
 *)
// backslash at end of line means join lines
let xx = "aa\
   bb"
printfn "%s" xx
// aabb
// single quote string with embeded QUOTATION MARK
let xx = "he said \"this\" and \"that\"."
printfn "%s" xx
// he said "this" and "that".

Triple Quoted string (Real Verbatim)

// triple quoted string example
let xx =  """some thing"""
printfn "%s" xx
// some thing
// backslash has no special meaning
let xx =  """some\nthing"""
printfn "%s" xx
// some\nthing
// backslash at end of line, no special meaning
let xx = """aa\
   bb"""
printfn "%s" xx
(*
aa\
   bb
 *)
// triple quoted string, example of multiple lines
let xx =  """some thing
in the water"""
printfn "%s" xx
(*
some thing
in the water
*)

Fsharp, String