String.forall Function (F#)
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)
// Signature:
String.forall : (char -> bool) -> string -> bool
// Usage:
String.forall predicate str
Parameters
-
The function to test each character of the string.
str
Type: stringThe input string.
Exceptions
Exception |
Condition |
---|---|
Thrown 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 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2
Version Information
F# Runtime
Supported in: 2.0, 4.0
Silverlight
Supported in: 3