[文字列を検索する]
文字列の中から、指定の文字列を探します。
【ソースコード】 [tips0019.pas]
program tips0019;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
strValue :String;
strFind :String;
AnsiValue :AnsiString;
AnsiFind :AnsiString;
begin
strValue := 'あいうえお';
strFind := 'い';
AnsiValue := AnsiString(strValue);
AnsiFind := AnsiString(strFind);
WriteLn('文字列「' + strValue + '」の「' + strFind + '」は');
WriteLn(' ' + IntToStr(Pos(strFind, strValue)) + ' 文字目です。');
WriteLn(' ' + IntToStr(Pos(AnsiFind, AnsiValue)) + ' バイト目です。');
WriteLn(' ' + IntToStr(AnsiPos(strFind, strValue)) + ' 文字目です。');
WriteLn(' ' + IntToStr(AnsiPos(AnsiFind, AnsiValue)) + ' 文字目です。');
end.
【コンパイル&実行】 [tips0019.bat]
dcc32 tips0019.pas
tips0019.exe > tips0019.txt
pause
【実行結果】 [tips0019.txt]
文字列「あいうえお」の「い」は
2 文字目です。
3 バイト目です。
2 文字目です。
2 文字目です。
Copyright c 2009, ohishi,All rights reserved.