Text.PositionOf

構文

Text.PositionOf(text as text, substring as text, optional occurrence as nullable number, optional comparer as nullable function) as any

バージョン情報

text の中でテキスト値 substring が出現する位置を返します。 任意のパラメーター occurrence を使用すれば、返す出現位置 (既定では最初の出現) を指定できる場合もあります。 substring が見つからなかった場合、-1 を返します。

comparerComparer であり、比較の制御に使用されます。 比較子を使用して、大文字と小文字を区別しない、またはカルチャおよびロケールに対応する比較を行うことができます。

数式言語では、次の組み込みの比較子を使用できます。

  • Comparer.Ordinal:序数に基づく正確な比較を実行するために使用されます
  • Comparer.OrdinalIgnoreCase:序数に基づき、大文字と小文字を区別しない正確な比較を実行するために使用されます
  • Comparer.FromCulture: カルチャ対応の比較を実行するために使います

例 1

次のテキスト内で、"World" の最初の出現位置を取得します。"Hello, World! Hello, World!"。

使用方法

Text.PositionOf("Hello, World! Hello, World!", "World")

出力

7

例 2

次のテキスト内で、"World" の最後の出現位置を取得します。"Hello, World! Hello, World!"。

使用方法

Text.PositionOf("Hello, World! Hello, World!", "World", Occurrence.Last)

出力

21