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 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2
Version Information
F# Runtime
Supported in: 2.0, 4.0
Silverlight
Supported in: 3