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

String.forall Function (F#)

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

Tests if all characters in the string satisfy the given predicate.

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

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

Syntax

// Signature:
String.forall : (char -> bool) -> string -> bool

// Usage:
String.forall predicate str

Parameters

predicate Type: char->bool

The function to test each character of the string.

str Type: string

The input string.

Exceptions

ExceptionCondition
ArgumentNullExceptionThrown when the input string is null.

Return Value

Returns true if all characters return true for the predicate and false otherwise.

Remarks

This function is named ForAll 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.forall.


let isWholeNumber string1 =
    if (String.forall (fun c -> System.Char.IsDigit(c)) string1) then
        printfn "The string \"%s\" is a whole number." string1
    else
        printfn "The string \"%s\" is not a valid whole number." string1
isWholeNumber "8005"
isWholeNumber "512"
isWholeNumber "0x20"
isWholeNumber "1.0E-5"
isWholeNumber "-20"

Output

The string "8005" is a whole number.
The string "512" is a whole number.
The string "0x20" is not a valid whole number.
The string "1.0E-5" is not a valid whole number.
The string "-20" is not a valid whole number.

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