お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"ニフティのログをヘッダかどうか判定"





文字列 S がニフティの会議室の発言ヘッダならTrue、違えばFalseを返す。
Trueの時 No には発言番号が入る。Falseの時Noは不定

function IsNifHeader(const S:string;var No:Integer):Boolean;
const
  Num : Set of Char = ['0'..'9'];  // 数字、const 宣言しないほうがホントは速い
  ALPH: Set of Char = ['A'..'Z'];  // 英大文字
var
  Cycl:Boolean;   //サイクリックならTrue;
begin
  Result:=False ;
  if Length(S) < 40 then Exit;
     //まず文字数でふるいをかける、以後 S[1..40] の配列としてアクセス可能
  Cycl:=S[6]='/';   // サイクリックかどうかチェック
  if (not Cycl) and (s[4]<>'/') then Exit; 
    //ここまでのチェックで99%以上落とせる。
       //つまり、以降の処理は多少遅くても影響は少ない。
  if Cycl
    then Result:=(s[12]=' ')
           and   (s[ 7] in Num)
           and   (s[10] in Num)
           and   (s[13] in ALPH)
           and   (s[14] in ALPH)
           and   (s[15] in ALPH)
           and   (s[16] in Num)
    else Result:=(s[8]=' ')
           and   (s[5]  in Num) 
           and   (s[11] in ALPH)
           and   (s[12] in ALPH)
           and   (s[13] in ALPH)
           and   (s[14] in Num)
           and   (s[16] in Num);
  if Result then begin
    No:=StrToIntDef(Copy(S,1,3+byte(Cycl)*2),-1);
     //例外処理を使ってもいいけど...
    Result := No <> -1;  //変換に失敗したらFalse
  end;
end;

                       97/10/20(月) 04:28 べあ(BYI15773)

Original document by べあ            氏 ID:(BYI15773)


ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum