大/小文字を無視してサブストリングの索引を取得します。
パラメータ | 説明 |
---|---|
searchString | 検索対象のサブストリング。 |
position | このオブジェクトでの検索開始位置。デフォルトの位置は 0 です。 |
戻り値 | 説明 |
---|---|
int | 位置 0 に対して相対的なサブストリングの位置、またはサブストリングが見つからない場合は -1。 |
var cities = new String("Paris Moscow Tokyo");
var n = cities.indexOfIgnoreCase("moscow");
if (n >= 0) {
return cities.substring(n);
} else {
return "moscow not found";
}
(2) この例では、大/小文字を無視してストリングで moscow の登場回数を数えます。
var cities = new String("Paris Moscow Tokyo Moscow");
var counter = 0;
var n = cities.indexOfIgnoreCase("moscow");
while (n >= 0) {
counter++;
n = cities.indexOfIgnoreCase("moscow", n + 1);
}
return "Number of occurrences of moscow = " + counter