String.exists Function (F#)

Tests if any character of the string satisfies the given predicate.

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

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

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

// Usage:
String.exists predicate str

Parameters

  • predicate
    Type: char -> bool

    The function to test each character of the string.

  • str
    Type: string

    The input string.

Exceptions

Exception

Condition

ArgumentNullException

Thrown when the input string is null.

Return Value

Returns true if any character returns true for the predicate and false otherwise.

Remarks

This function is named Exists 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.exists.

let containsUppercase string1 =
    if (String.exists (fun c -> System.Char.IsUpper(c)) string1) then
        printfn "The string \"%s\" contains uppercase characters." string1
    else
        printfn "The string \"%s\" does not contain uppercase characters." string1
containsUppercase "Hello World!"
containsUppercase "no"

Output

The string "Hello World!" contains uppercase characters.
The string "no" does not contain uppercase characters.

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

Reference

Core.String Module (F#)

Microsoft.FSharp.Core Namespace (F#)