strExt是一个表示文件后缀名的字符串变量,判断strExt是否是(‘.exe‘,‘.rar‘,‘.zip‘,‘.pdg‘,‘.pdf‘,‘.chm‘等)之一.
能实现这个问题的语句如何写?能否用枚举与集合。

解决方案 »

  1.   

    if strext in (‘.exe‘,‘.rar‘,‘.zip‘,‘.pdg‘,‘.pdf‘,‘.chm‘)
      

  2.   

    if strext in (‘.exe‘,‘.rar‘,‘.zip‘,‘.pdg‘,‘.pdf‘,‘.chm‘)
    编译不通过,我最早也这样写,但不行
    编译时提示:')'expected but','found.光标停在第一个逗号之后。
      

  3.   

    字符串不行的,只能用if语句一个一个判断。
    或者建立一个TStringList来判断:
    var
      str: TStringList;
    begin
      str := TStringList.Create;
      str.CommaText := '.exe,.rar,.zip,.pdg,.pdf,.chm';
      if str.IndexOf(strExt) > 0 then ShowMessage('found');
      str.Free;
    end;