F# strings are immutable objects representing text as a sequence of Unicode characters (letters, digits, punctuation, etc.). Double quotes are used to define a string
instance:
let fruit = "Apple"
Manipulating a string can be done by calling one of its methods or properties, or using one of the functions in the String
module. As string values can never change after having been defined, all string manipulation methods/functions will return a new string.
A string is delimited by double quote ("
) characters. Some special characters need escaping using the backslash (\
) character. Strings can also be prefixed with the at (@
) symbol, which makes it a verbatim string that will ignore any escaped characters.
let escaped = "c:\\test.txt"
let verbatim = @"c:\test.txt"
escaped = verbatim
// => true
Alternatively, strings can be defined using triple quotes ("""
), which allows using a double quote in the string without escaping it.
let tripledQuoted = """<movie title="Se7en" />"""
// => "<movie title="Se7en" />
Finally, concatenating strings can be done through the +
operator:
let name = "Jane"
"Hello" + name + "!"
// => "Hello Jane!"