次の方法で共有


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 を返します。

comparer は、比較を制御するために使用される Comparer です。 比較子を使用して、大文字と小文字を区別しない、またはカルチャとロケールに対応した比較を提供できます。

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

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

例 1

Get the position of the first occurrence of "World" in the text "Hello, World! Hello, World!".

使用方法

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

アウトプット

7

例 2

Get the position of last occurrence of "World" in "Hello, World! Hello, World!".

使用方法

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

アウトプット

21