掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
指定した文字列が対象文字列の中にいくつ存在するかをチェックするについて (ID:148999)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
直接的にそのような動作をするものはないですね。 案1: Pos http://docwiki.embarcadero.com/Libraries/Tokyo/ja/System.Pos で文字列末尾までスキャンする procedure TForm1.Button1Click(Sender: TObject); var Source: String; Sub: String; I: Integer; Count: Integer; begin Source := 'AAAA-BBBB-CCCC-DDDD-EEEE'; Sub := '-'; Count := 0; I := 1; while True do begin I := Pos(Sub,Source,I); if I = 0 then begin Break; end; Count := Count + 1; I := I + Length(Sub); end; Label1.Caption := IntToStr(Count); end; 案2: 正規表現ライブラリ http://docwiki.embarcadero.com/Libraries/Tokyo/ja/System.RegularExpressions.TRegEx を使う uses System.RegularExpressions; procedure TForm1.Button2Click(Sender: TObject); var Source: String; Sub: String; Count: Integer; begin Source := 'AAAA-BBBB-CCCC-DDDD-EEEE'; Sub := '-'; Count := TRegEx.Matches(Source,Sub).Count; Label1.Caption := IntToStr(Count); end;
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.