Ver Mensaje Individual
  #5  
Antiguo 01-12-2010
Avatar de Estifmauin
Estifmauin Estifmauin is offline
Miembro
 
Registrado: may 2008
Ubicación: Alicante
Posts: 24
Reputación: 0
Estifmauin Va por buen camino
Otro enfoque, más legible, pero creo que menos eficiente:

Código Delphi [-]
function SoloNumeros(s:string):string;
var
  n :integer;
begin
  result:='';
  n:=1;
  while (n <= Length(s))
  and (s[n] in ['0'..'9']) do begin
    result:=result+s[n];
    Inc(n);
  end;
end;

function ExtraerNumeros(cadena, prefijo :string) :TStrings;
var
  i :integer;
begin
  result:=TStringList.Create;
  result.CommaText:=StringReplace(cadena,prefijo,',',[rfReplaceAll]);
  for i:=result.Count -1 downto 0 do begin
    result[i]:=SoloNumeros(result[i]);
    if result[i] = '' then result.Delete(i);
  end;
end;
Para llamarlo:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
  memo1.Lines:=ExtraerNumeros('HGL44DHS274HGL23JHGL41234HGL412YGHGL555XADSF1AHG12HGL999','HGL');
end;
Es más legible, pero insisto en que menos eficiente, y requiere uses StrUtils
Responder Con Cita