Ver Mensaje Individual
  #1  
Antiguo 24-02-2015
JuanOrtega JuanOrtega is offline
Miembro
NULL
 
Registrado: sep 2011
Posts: 130
Reputación: 13
JuanOrtega Va por buen camino
Funcion split en Delphi

Hola tengo la siguiente funcion split en Delphi que funciona perfecto el problema es quiero mejorar el codigo para no usar mas repeat-until pero no se de que otra forma hacerlo.

El codigo es este :

Código Delphi [-]

type
  TSarray = array of string;

function Split(Texto, Delimitador: string): TSarray;

var
  o: integer;
  PosDel: integer;
  Aux: string;

begin

  o := 0;
  Aux := Texto;
  SetLength(Result, Length(Aux));

  repeat

    PosDel := Pos(Delimitador, Aux) - 1;

    if PosDel = -1 then
    begin
      Result[o] := Aux;
      break;
    end;

    Result[o] := copy(Aux, 1, PosDel);
    delete(Aux, 1, PosDel + Length(Delimitador));
    inc(o);
  until Aux = '';
end;

Un ejemplo de uso :

Código Delphi [-]
var texto,deli:string;
    all_array:TSarray;
begin
deli := 'test';
texto := deli+'hi world 1'+deli+'hi world 2'+deli;
end;

all_array := Split(texto,deli);
ShowMessage(all_array[1]);
ShowMessage(all_array[2]);
end;

¿ Que alternativas tengo ante repeat-until ?

Última edición por JuanOrtega fecha: 24-02-2015 a las 16:23:36.
Responder Con Cita