var
str:string;
iCode:integer;
begin
   str:='XX市第5区第9街第10组';
怎样得到上面的5/9/10啊?还有如果5为15或更多位数,怎么处理?

解决方案 »

  1.   

    const number:string='1234567890';  
    var
    str:string;
    iCode:integer;
    bNum:boolean;
    out:string;  //输出结果
    begin
       str:='XX市第5区第9街第10组';
       bNum:=false;
       out:='';
       for i:=1 to Length(str) do begin
         if str(i) in number then begin
           if bNum then
             out:=out+str(i)
           else begin
              out:=str(i)
              bNum:=true;
           end;
         end
         else begin
           bNum:=false;
           if out<>'' then
              ...//处理Out
         end;
      end;
    end;
      

  2.   

    进行字符比较,即把str看作字符数组,然后利用循环可得到每一个字符,比较该字符是否在'0'和'9'之间,注意进行字符比较。如果连续,就写在一起。这是一个苯办法,但比较容易实现。
      

  3.   

    agree,先求出它的字符串长度然后循環,是数字的话就输出来
    我也只知道这样
      

  4.   

    //这样简单的算法应该自己写写,否则怎么提高自己??~~
    //没事写着玩~~function Extraction(mStr: string; mSet: TSysCharSet; mDelimiter: string): string;
    var
      I: Integer;
      B: Boolean;
    begin
      Result := '';
      B := False;
      for I := 1 to Length(mStr) do
        if mStr[I] in mSet then begin
          if B then
            Result := Result + mStr[I]
          else Result := Result + mDelimiter + mStr[I];
          B := True;
        end else B := False;
      Delete(Result, 1, Length(mDelimiter));
    end; { Extraction }procedure TForm1.Button1Click(Sender: TObject);
    var
      Str: string;
    begin
      Str := 'XX市第1251区第92街第10组';
      Caption := Extraction(Str, ['0'..'9'], '/');
    end;
      

  5.   

    zswangII(伴水清清)(职业清洁工)想来是伴水灌水太多从二星降到四条内裤
      

  6.   

    该用正则表达式,ActiveX对象
      

  7.   

    function getnum(str:string):string;
    var
      i,j:integer;
    begin
      result:='';
      i:=0;
      while(i<=length(str)) do
      begin
        inc(i);
        if not (str[i] in ['0'..'9']) then
          continue;
        for j:=i to length(str) do
          if str[j] in ['0'..'9'] then
            result:=result+str[j]
          else
          begin
            result:=result+'\';
            i:=j;
            break;
          end;
      end;
    end;测试如下 输入5E23a1111sd2dit1
    输出 5\23\1111\2\1
    从 5\23\1111\2\1导出integer数组的函数写起来也很容易
      

  8.   

    to:: qinmaofan(采菊南山下 &lt;抵制日货 从我做起
    代码错太多
      

  9.   

    我太粗心了
    刚才有空重新写了一下procedure TForm1.Button1Click(Sender: TObject);
    const number:string='1234567890';  
    var
    str:string;
    iCode:integer;
    bNum:boolean;
    i:integer;
    outstr:string;  //输出结果
    begin
       str:='XX市第5区第9街第10组';
       bNum:=false;
       outstr:='';
       for i:=1 to Length(str) do begin
         if pos(str[i],number)>0 then begin
           if bNum then
             outstr:=outstr+str[i]
           else begin
              outstr:=str[i];
              bNum:=true;
           end;
         end
         else begin
           bNum:=false;
           if outstr<>'' then begin
             showmessage(outstr);
             outstr:='';
           end;
         end;
      end;
    end;