Instr (MDX)
ある文字列が別の文字列内で最初に出現する位置を返します。
構文
InStr([start, ]searched_string, search_string[, compare])
引数
start
(省略可能)各検索の開始位置を設定する数式。 この値を省略すると、検索は最初の文字位置から開始されます。 start が null の場合、関数の戻り値は未定義となります。
searched_string
検索範囲となる文字列式。
search_string
検索する文字列式。
比較
(省略可) 整数値です。 この引数は常に無視されます。 これは、他の言語の他 の Instr 関数との互換性のために定義されています。
戻り値
String1 の String2 の開始位置を持つ整数値。
また、 InStr 関数は、条件に応じて、次の表に示す値を返します。
条件 | 戻り値 |
---|---|
String1 の長さが 0 | 0 (0) |
String1 が NULL | undefined |
String2 は長さ 0 です | start |
String2 が NULL | undefined |
String2 が見つからない | 0 (0) |
start が Len(String2) より大きい | 0 (0) |
解説
警告
Instr では 、常に大文字と小文字を区別しない比較が実行されます。
例
次の例は 、Instr 関数の使用方法を示し、さまざまな結果シナリオを示しています。
with
member [Date].[Date].[Results] as "Results"
member measures.[lowercase found in lowercase string] as InStr( "abcdefghijklmnñopqrstuvwxyz", "o")
member measures.[uppercase found in lowercase string] as InStr( "abcdefghijklmnñopqrstuvwxyz", "O")
member measures.[searched string is empty] as InStr( "", "o")
member measures.[searched string is null] as iif(IsError(InStr( null, "o")), "Is Error", iif(IsNull(InStr( null, "o")), "Is Null","Is undefined"))
member measures.[search string is empty] as InStr( "abcdefghijklmnñopqrstuvwxyz", "")
member measures.[search string is empty start 10] as InStr(10, "abcdefghijklmnñopqrstuvwxyz", "")
member measures.[search string is null] as iif(IsError(InStr( null, "o")), "Is Error", iif(IsNull(InStr( null, "o")), "Is Null","Is undefined"))
member measures.[found from start 10] as InStr( 10, "abcdefghijklmnñopqrstuvwxyz", "o")
member measures.[NOT found from start 17] as InStr( 17, "abcdefghijklmnñopqrstuvwxyz", "o")
member measures.[NULL start] as iif(IsError(InStr( null, "abcdefghijklmnñopqrstuvwxyz", "o")), "Is Error", iif(IsNull(InStr( null, "abcdefghijklmnñopqrstuvwxyz", "o")), "Is Null","Is undefined"))
member measures.[start greater than searched length] as InStr( 170, "abcdefghijklmnñopqrstuvwxyz", "o")
select [Results] on columns,
{ measures.[lowercase found in lowercase string]
, measures.[uppercase found in lowercase string]
, measures.[searched string is empty]
, measures.[searched string is null]
, measures.[search string is empty]
, measures.[search string is empty start 10]
, measures.[search string is null]
, measures.[found from start 10]
, measures.[NOT found from start 17]
, measures.[NULL start]
, measures.[start greater than searched length]
} on rows
from [Adventure Works]
取得した結果を次の表に示します。
メジャー内のフィールド | 結果 |
---|---|
小文字の文字列で小文字が見つかりました | 16 |
小文字の文字列で大文字が見つかりました | 16 |
検索した文字列が空 | 0 |
検索された文字列が null です | 未定義 |
検索文字列が空です | 1 |
検索する文字列が開始位置 10 から空 | 10 |
検索する文字列が NULL | 未定義 |
開始位置 10 から検索 | 16 |
開始 17 から見つかりません | 0 |
NULL で開始 | 未定義 |
start が検索された長さより大きい | 0 |
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示