如何判断字符串前四位是正确的年度?谢谢!

解决方案 »

  1.   

    方法一:使用正则表达式
    方法二:根据你自己的情况,将字符串前四位子串copy出,然后在try  except 中通过strtoint等方法进行判断。
      

  2.   

    LeftStr可以取得字符串从左开始的字符串。
      

  3.   

    if Copy(字符串,1,4)>='' and Copy(字符串,1,4)<='' then
      showmessage('正确年度')
      

  4.   

    var
      csY  : string;
      Year : word;
    begin
      csY := Copy( DateStr, 1, 4 );
      Year:= StrToIntDef( csY, 0 );
      if year = 0 then exit;  //error