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

String.init Function (F#)

Den Delimarsky|Last Updated: 7/25/2016
|
1 Contributor

Creates a new string whose characters are the results of applying a specified function to each index and concatenating the resulting strings.

Namespace/Module Path: Microsoft.FSharp.Core.String

Assembly: FSharp.Core (in FSharp.Core.dll)

Syntax

// Signature:
String.init : int -> (int -> string) -> string

// Usage:
String.init count initializer

Parameters

count Type: int

The number of strings to initialize.

initializer Type: int->string

The function to take an index and produce a string to be concatenated with the others.

Exceptions

ExceptionCondition
ArgumentExceptionThrown when count is negative.

Return Value

The constructed string.

Remarks

This function is named Initialize in compiled assemblies. If you are accessing the function from a .NET language other than F#, or through reflection, use this name.

Example


    let string1 = String.init 10 (fun i -> i.ToString())
    printfn "%s" string1
    let string2 = String.init 26 (fun i ->
        sprintf "%c" (char (i + int 'A')))
    printfn "%s" string2

Output

0123456789
ABCDEFGHIJKLMNOPQRSTUVWXYZ

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

See Also

Core.String Module (F#)

Microsoft.FSharp.Core Namespace (F#)

© 2017 Microsoft