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

String.exists Function (F#)

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

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)

Syntax

// 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

ExceptionCondition
ArgumentNullExceptionThrown 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

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

Core.String Module (F#)

Microsoft.FSharp.Core Namespace (F#)

© 2018 Microsoft