Export (0) Print
Expand All

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

predicate

Type: char -> bool

The function to test each character of the string.

str

Type: string

The input string.

Exception

Condition

ArgumentNullException

Thrown when the input string is null.

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

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.

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.

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Show:
© 2014 Microsoft