共用方式為


String.forall 函式 (F#)

更新:2010 年 8 月

測試字串中的所有字元是否都滿足指定的述詞。

命名空間/模組路徑: Microsoft.FSharp.Core.String

組件:FSharp.Core (在 FSharp.Core.dll 中)

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

// Usage:
String.forall predicate str

參數

  • predicate
    型別:char -> bool

    用來測試字串的每一個字元的函式。

  • str
    型別:string

    輸入字串。

例外狀況

例外狀況

條件

ArgumentNullException

當輸入字串為 null 時擲回。

傳回值

傳回 true如果傳回所有字元 true的述詞和 false否則

備註

這個函式是名為 ForAll中 已編譯的組件。 如果從一個語言,F # 以外,或透過反映存取函式使用這個名稱。

範例

下列程式碼會示範如何使用 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"

輸出

            

平台

Windows 7、Windows Vista SP2、Windows XP SP3、Windows XP x64 SP2、Windows Server 2008 R2、Windows Server 2008 SP2、Windows Server 2003 SP2

版本資訊

F# 執行階段

支援版本:2.0、4.0

Silverlight

支援版本:3

請參閱

參考

Core.String 模組 (F#)

Microsoft.FSharp.Core 命名空間 (F#)

變更記錄

日期

History

原因

2010 年 8 月

加入程式碼範例。

資訊加強。