很急,谢谢!

解决方案 »

  1.   

    var s, s1: string;  i: integer;
    begin
     s := '#1#122#12#2223434';
     for i := 1 to Length(s) do
     begin
       if ord(s[i]) in [$30..$39] then
        s1 := s1 + s[i]
       else
       begin
         if Length(s1)> 0 then
          ShowMessage(s1);
         s1 := '';
       end;
     end;
          if Length(s1)> 0 then
          ShowMessage(s1);
    end;
      

  2.   

    首先你写的“字符串s='?'#1#1#1#2”是不是字符串s='?#1#1#1#2'还是字符串s='''?''#1#1#1#2'
    虽然不清楚还是回答一下
    如果格式固定(前面有一个?,后面用#分割数字--数字随便是多少)则可做一函数:function getdivedstr(ostr,divstr:string;var aimstr: Tstrings):boolean;
    var //用divstr将ostr分割后,把得到的子字符放到字符数组aimstr中
     i,n,j:integer;
     p: array of integer;
     nstr,xstr:string;
    begin
     n:= strlen(pchar(ostr));
     j:=0;
    try
     for i:=1 to n do
      if MidBStr(ostr,i,1)=divstr then begin
       j:=j+1;
       SetLength(p,j);
       p[j-1]:=i;//得到第j-1个字符是divstr
      end;                   
     if j>0 then aimstr.add(LeftBStr(ostr,p[0]-1));
     for i:=1 to j-1 do begin
       nstr:= MidBStr(ostr,p[i-1]+1,p[i]-p[i-1]-1);
       aimstr.Add(nstr);
     end;
     nstr:= RightBStr(ostr,strlen(pchar(ostr))-p[j-1]);
     aimstr.Add(nstr);
     result:=true;
    except
    result:=false;
    end;得到字符数组aimstr中第一个元素为'?'从第二个元素开始为数字(用时可从字符转为数字--inttostr)
      

  3.   

    function nums(s:string):integer;
    var
      i,j:integer;
      str:string;begin
      str:= '' ;
      for i := 1 to Length(s) do
       if TryStrToInt(s[i],j) then
         str:=str+s[i];
      result StrToInt(str) ;
    end;
      

  4.   

    给你一个最好用的
    function GetDigit(const str:string):string;
    var
    i:integer;
    begin
     for i:=1 to length(str) do
      begin
        if str[i] in ['0'..'9'] Then
         Result:=Result+Str[i];
      end;
    end;
      

  5.   

    function GetDigit(const str:string):string;
    var
    i:integer;
    begin
     for i:=1 to length(str) do
      begin
        if str[i] in ['0'..'9'] Then
         Result:=Result+Str[i];
      end;
    end;
    同意
      

  6.   

    procedure TForm1.Button1Click(Sender: TObject);
    var s, s1: string;  i, J: integer;
    begin
     s := '?'#1#1#1#2'  ';
     for i := 1 to Length(s) do
     begin
       j := ord(s[i]);
     //  showMessage(IntToStr(j));
       if j < 9 then
        s1 := s1 + IntToStr(j)
       else
       begin
         if Length(s1)> 0 then
          ShowMessage(s1);
         s1 := '';
       end;
     end;
          if Length(s1)> 0 then
          ShowMessage(s1);
    end;
      

  7.   

    我同意使用
    function GetDigit(const str:string):string;
    var
    i:integer;
    begin
     for i:=1 to length(str) do
      begin
        if str[i] in ['0'..'9'] Then
         Result:=Result+Str[i];
      end;
    end;执行效率快
      

  8.   

    是在调试的时候看见的,发现这个字符串的length老是改变的,怎么办?