String.collect Function (F#)
Builds a new string whose characters are the results of applying a specified function to each of the characters of the input string and concatenating the resulting strings.
Namespace/Module Path: Microsoft.FSharp.Core.String
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
String.collect : (char -> string) -> string -> string
// Usage:
String.collect mapping str
Parameters
-
The function to produce a string from each character of the input string.
str
Type: stringThe input string.
Exceptions
Exception |
Condition |
---|---|
Thrown when the input string is null. |
Return Value
The concatenated string.
Remarks
This function is named Collect in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.
Example
The following code shows how to use String.collect.
let spaceOut inputString =
String.collect (fun c -> sprintf "%c " c) inputString
printfn "%s" (spaceOut "Hello World!")
Output
H e l l o W o r l d !
Platforms
Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2
Version Information
F# Core Library Versions
Supported in: 2.0, 4.0, Portable