index_of()
指定された文字の位置 (インデックス) を返します。
構文
index_of(string, searchStr [,position [, occurence]])
使用方法
この関数は、string 内の指定された position から searchStr のインデックスを返します。searchStr が見つからない場合は 0 が返されます。この関数では、大文字と小文字が区別されます。いずれかのパラメータが null の場合、関数は null を返します。
position のデフォルト値は 1 です。つまり、関数は string の最初の文字から検索を開始します。position が負または 0 の場合、エラーが発生します。
occurrence は、省略可能な整数です。デフォルト値は 1 です。このパラメータを使用して、出現するどの searchStr を検索対象にするかを指定できます。たとえば、複数の searchStr が出現する場合、occurence が 2 のときは、2 番目に出現した文字列のインデックスが返されます。
position および occurrence では定数値がサポートされ、任意の式はサポートされていません。
searchStr が空の文字列の場合、関数は null を返します。例
1-- return the first occurrence of "a", starting at the beginning.
2-- The result is 2.
3q = foreach q generate index_of("Hawaii", "a") as 'Index';
4
5-- return the second occurrence of "a", starting at the beginning
6-- the result is 4
7q = foreach q generate index_of("Hawaii", "a",1, 2) as 'Index';
8
9
10-- return the first occurrence of "a", starting at the third position
11-- the result is 4
12q = foreach q generate index_of("Hawaii", "a",3) as 'Index';