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

String.map Function (F#)

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

Creates a new string whose characters are the results of applying a specified function to each of the characters of the input string.

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

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

Syntax

// Signature:
String.map : (char -> char) -> string -> string

// Usage:
String.map mapping str

Parameters

mapping Type: char->char

The function to apply to the characters of the string.

str Type: string

The input string.

Exceptions

ExceptionCondition
ArgumentNullExceptionThrown when the input string is null.

Return Value

The resulting string.

Remarks

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

Example


let rot13 c =
    let upperZero = int 'A' - 1
    let lowerZero = int 'a' - 1
    if System.Char.IsLetter(c) then
        if System.Char.IsUpper(c) then
            char (((int c + 13 - upperZero) % 26) + upperZero)
        else
            char (((int c + 13 - lowerZero) % 26) + lowerZero)
    else c
let test = "The quick sly fox jumped over the lazy brown dog."
printfn "%s" test
printfn "%s" <| (String.map rot13 test)

Output

The quick sly fox jumped over the lazy brown dog.
Gur dhvpx fyl sbk whzcrq bire gur ynml oebja qbt.

Platforms

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

Version Information

F# Core Library VersionsF# Core Library Versions

Supported in: 2.0, 4.0, Portable2.0, 4.0, Portable

See Also

Core.String Module (F#)

Microsoft.FSharp.Core Namespace (F#)

© 2017 Microsoft