Functional programming operators for string processing. Further string operations are available via the member functions on strings and other functionality in System.String and System.Text.RegularExpressions types.
Function or value | Description | ||
|
![]() ![]() ![]() ![]() ![]() ![]()
Builds a new string whose characters are the results of applying the function
ExampleThe following samples shows how to interspace spaces in a text let input = "Stefan says: Hi!" input |> String.collect (sprintf "%c ")The sample evaluates to "S t e f a n s a y s : H i ! "
ExampleHow to show the ASCII representation of a very secret text "Secret" |> String.collect (fun chr -> int chr |> sprintf "%d ")The sample evaluates to "83 101 99 114 101 116 "
|
||
Full Usage:
String.concat sep strings
Parameters:
string
-
The separator string to be inserted between the strings
of the input sequence.
strings : seq<string>
-
The sequence of strings to be concatenated.
Returns: string
A new string consisting of the concatenated strings separated by
the separation string.
|
![]() ![]() ![]() ![]() ![]() ![]()
Returns a new string made by concatenating the given strings
with separator
Example
let input1 = ["Stefan"; "says:"; "Hello"; "there!"] input1 |> String.concat " " // evaluates "Stefan says: Hello there!" let input2 = [0..9] |> List.map string input2 |> String.concat "" // evaluates "0123456789" input2 |> String.concat ", " // evaluates "0, 1, 2, 3, 4, 5, 6, 7, 8, 9" let input3 = ["No comma"] input3 |> String.concat "," // evaluates "No comma" |
||
|
ExampleLooking for uppercase characters open System "Yoda" |> String.exists Char.IsUpper // evaluates true "nope" |> String.exists Char.IsUpper // evaluates false |
||
|
![]() ![]() ![]() ![]() ![]() ![]() Builds a new string containing only the characters of the input string for which the given predicate returns "true". Returns an empty string if the input string is null
ExampleFiltering out just alphanumeric characters open System let input = "0 1 2 3 4 5 6 7 8 9 a A m M" input |> String.filter Uri.IsHexDigit // evaluates "123456789aA" ExampleFiltering out just digits open System "hello" |> String.filter Char.IsDigit // evaluates "" |
||
|
ExampleLooking for lowercase characters open System "all are lower" |> String.forall Char.IsLower // evaluates false "allarelower" |> String.forall Char.IsLower // evaluates true |
||
|
![]() ![]() ![]() ![]() ![]() ![]()
Builds a new string whose characters are the results of applying the function
ExampleEnumerate digits ASCII codes String.init 10 (fun i -> int '0' + i |> sprintf "%d ")The sample evaluates to: "48 49 50 51 52 53 54 55 56 57 "
|
||
|
ExamplePrinting the ASCII code for each characater in the string let input = "Hello" input |> String.iter (fun c -> printfn "%c %d" c (int c))The sample evaluates as unit , but prints:
H 72 e 101 l 108 l 108 o 111 |
||
|
ExampleNumbering the characters and printing the associated ASCII code for each characater in the input string let input = "Hello" input |> String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c))The sample evaluates as unit , but prints:
1. H 72 2. e 101 3. l 108 4. l 108 5. o 111 |
||
|
ExampleGetting the length of different strings String.length null // evaluates 0 String.length "" // evaluates 0 String.length "123" // evaluates 3 |
||
|
![]() ![]() ![]() ![]() ![]() ![]()
Builds a new string whose characters are the results of applying the function
ExampleChanging case to upper for all characters in the input string open System let input = "Hello there!" input |> String.map Char.ToUpper // evaluates "HELLO THERE!" |
||
![]() ![]() ![]() ![]() ![]() ![]()
Builds a new string whose characters are the results of applying the function
Example
input |> String.mapi (fun i c -> (i, c))Evaluates to [ (0, 'O'); (1, 'K'); (2, '!') ] .
|
|||
|
Example
"Do it!" |> String.replicate 3Evaluates to "Do it!Do it!Do it!" .
|