Fsharp: String
What is String
- String type's value is sequence of Unicode Characters.
- String is immutable. (once created, it cannot change.)
string
is an alias forSystem.String
in dotnet.
Single Quoted String
- String can be quoted by QUOTATION MARK. E.g.
"abc"
- Inside, backslash has special meaning, known as Escape Sequence. E.g.
\n
means a newline,\"
is QUOTATION MARK. - Backslash at end of line has special meaning. It joins next line and removes any white space in beginning of next line.
// 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)
- Syntax is 3 quotation marks. E.g.
"""abc"""
- Backslash has no special meaning.
// 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 *)