比如:'CN009'第三个字符就是数字了,那我怎么判断它?
即是说,这代码该怎么写?
谢谢!

解决方案 »

  1.   

    function haveNum(s:string):boolean;
    var
      i:integer;
    begin
      result:=false;
      for i:=1 to length(s) do
      if s[i] in ['0'..'9'] then begin
         result:=true;
         exit;
      end;
    end;
      

  2.   

    用ORD()函数,用一个FOR语句判断它是否属于字母
      

  3.   

    那如果我用定位的话,应该怎么来写呢?
    --------------------------------
    那样就把senfore(来而不往非礼也!) 的答案改写一下就可以了
    function haveNum(s:string):integer;
    var
      i:integer;
    begin
      result:=false;
      for i:=1 to length(s) do
      if s[i] in ['0'..'9'] then begin
         result:=i;           //返回数字所在的位置
         exit;
      end;
      else
      result:=-1;            //如果没有找到返回-1
    end;
      

  4.   

    如果你只是想判断字串中是否存在0-9的数字,用senfore的方法就可以了
    如果你想得到全部数字,用以下函数:function HaveNum(s: string): integer;
    var
      i: integer;
      lResult: string;
    begin
      i := -1;
      lResult := '';
      for i := 1 to Length(s) do
        if s[i] in ['0'..'9'] then
          lResult := lResult + s[i];
      Result := StrToInt(lResult);
    end;
      

  5.   

    考虑API函数:
    IsCharAlpha和IsCharAlphaNumeric