Share via


String.mapi 関数 (F#)

入力文字列の各文字に指定された関数を適用し、その結果の文字から成る新しい文字列と、入力文字列のインデックスを作成します。

名前空間/モジュール パス: Microsoft.FSharp.Core.String

アセンブリ: FSharp.Core (FSharp.Core.dll 内)

// Signature:
String.mapi : (int -> char -> char) -> string -> string

// Usage:
String.mapi mapping str

パラメーター

  • mapping
    型: int -> char -> char

    文字列の各文字とインデックスに適用する関数。

  • str
    型: string

    入力文字列。

例外

例外

状態

ArgumentNullException

入力文字列が null の場合にスローされます。

戻り値

結果の文字列。

解説

この関数は、コンパイルされたアセンブリでは MapIndexed という名前です。 F# 以外の言語から、またはリフレクションを使用してこの関数にアクセスする場合は、この名前を使用します。

使用例

String.mapi の使用方法を次のコードに示します。

let replaceNth n newChar inputString =
    let result = String.mapi (fun i c -> if i = n then newChar else c) inputString
    printfn "%s" result
    result
printfn "MASK" 
"MASK" |> replaceNth 0 'B'
|> replaceNth 3 'H'
|> replaceNth 2 'T'
|> replaceNth 1 'O'
|> replaceNth 0 'M'
|> replaceNth 1 'A'
|> replaceNth 2 'S'
|> replaceNth 3 'K'

出力

  

プラットフォーム

Windows 8、Windows 7、Windows Server 2012 で Windows Server 2008 R2Windows 8、Windows 7、Windows Server 2012 で Windows Server 2008 R2

バージョン情報

F# コア ライブラリ VersionsF# コア ライブラリのバージョン

サポート: 2.0、4.0、Portable2.0、ポータブル 4.0

参照

関連項目

Core.String モジュール (F#)

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