Delphiで文字列の配列の中に、指定した文字列があるか調べる

System.StrUtils.MatchStr

MatchStrは、文字列の配列の中に指定した文字列があるときはTrueを返します。

この関数は、大文字と小文字を区別します。

uses
  System.StrUtils;

const
  Strings: array[0..2] of string = ('foo', 'bar', 'bazz');

if MatchStr('bar', Strings) then //=> True
  …

if MatchStr('BAR', Strings) then //=> False
  …

System.StrUtils.MatchText

MatchTextは、文字列の配列の中に指定した文字列があるときはTrueを返します。

この関数は、大文字と小文字を区別しません。

uses
  System.StrUtils;

const
  Strings: array[0..2] of string = ('foo', 'bar', 'bazz');

if MatchText('bar', Strings) then //=> True
  …

if MatchText('BAR', Strings) then //=> True
  …

if MatchText('Hoge', Strings) then //=> False
  …

System.StrUtils.IndexStr

IndexStrは、文字列の配列の中に指定した文字があるときはインデックスを返します。一致する文字列がないときは-1を返します。

この関数は、大文字と小文字を区別します。

uses
  System.StrUtils;

const
  Strings: array[0..2] of string = ('foo', 'bar', 'bazz');

WriteLn(IndexStr('bar', Strings)); //=> 1
WriteLn(IndexStr('BAR', Strings)); //=> -1
WriteLn(IndexStr('Hoge', Strings)); //=> -1

System.StrUtils.IndexText

IndexTextは、

この関数は、大文字と小文字を区別しません。

uses
  System.StrUtils;

const
  Strings: array[0..2] of string = ('foo', 'bar', 'bazz');

WriteLn(IndexText('bar', Strings)); //=> 1
WriteLn(IndexText('BAR', Strings)); //=> 1
WriteLn(IndexText('Hoge', Strings)); //=> -1

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください