Table of contents
Collapse the table of content
Expand the table of content

String.collect Function (F#)

Den Delimarsky|Last Updated: 8/18/2017
1 Contributor

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


mapping Type: char->string

The function to produce a string from each character of the input string.

str Type: string

The input string.


ArgumentNullExceptionThrown when the input string is null.

Return Value

The concatenated string.


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.


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!")


H e l l o   W o r l d !


Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Core.String Module (F#)

Microsoft.FSharp.Core Namespace (F#)

© 2020 Microsoft