Ver Mensaje Individual
  #13  
Antiguo 03-12-2010
McK McK is offline
Miembro
NULL
 
Registrado: oct 2010
Posts: 33
Reputación: 0
McK Va por buen camino
Thumbs up

Cita:
Empezado por ecfisa Ver Mensaje
Un detalle McK, si bien no me pasó lo del bucle infinito, descubrí un fallo en el código.

En la cadena anterior:

Si usas: ExtractNum('AS', Cadena) -> te devuelve: 'B'.

Es por que inicialicé mal el contador de ocurrencias numéricas y si o sí me pone un caracter aunque no sea un número.
Hay que inicializar distinto a 'i':
Código Delphi [-]... begin Inc(p, Length(Sub)); // i:= 1; BORRAR LINEA i:= 0; // NUEVA LINEA ...



Un saludo.
Vaaaaale ya sé lo que pasaba!!! Que despiste.... lo de i:= 0 ya me dí cuenta cuando lo depuraba..

Código:
function ExtractNum(Sub, Str: string): TStrings;
var
  i, p: Integer;
begin
  Result:= TStringList.Create;
  p:= 1;
  while p <> 0 do
  begin
    p:= Pos(Sub, Str);
    if p > 0 then
    begin
      Inc(p, Length(Sub));
      i:= 1;
      while Str[p + i] in ['0'..'9'] do Inc(i);
      Result.Add(Copy(Str, p, i));
      Inc(p, i);
      Str:= Copy(Str, p, MaxInt); // Esta línea no la había metido!!!  
    end;                          // De todas formas en mi procedure he metido esto tal cual sin crear ninguna función
  end;                            // y por no modificar mi cadena por eso he utilizado el auxiliar.
end;
Mil gracias y perdona por el mareo!!
Saludos
Responder Con Cita