Underc0de

Programación General => Delphi => Mensaje iniciado por: Expermicid en Julio 09, 2012, 05:34:26 PM

Título: sSplitDirigido [By Expermicid]
Publicado por: Expermicid en Julio 09, 2012, 05:34:26 PM
Hola a todos, aqui les dejo un reemplazo de la funcion split.
Pasandole como parametros el texto de entrada, un delimitador y una posicion te devuelve el elemento que se encuentra en esa posicion.
Aqui les dejo para que lo entiendan mejor. :)

(http://i.imgur.com/RRYFI.gif)

Código (delphi) [Seleccionar]
//  Autor : Expermicid
//  Fecha : 10/07/2012
//  Alternativa a Split
//  Forma de uso : sSplitDirigido(Texto,Delimitador,Elemento)
function sSplitDirigido( Input : String; Delimit : String; Index : Integer) : String;
  var
    aux : String;
    i : Integer;
  begin
    if Input = '' then Exit;
    if Delimit = '' then Exit;
    aux := Input;
    if Index > 0 then
      begin
        i := 0 ;
        while i < Index do
          begin
            if pos(Delimit, aux) <> 0 then
              aux := Copy(aux, pos(Delimit, aux) + Length(Delimit), Length(aux) - (pos(Delimit, aux) + Length(Delimit) - 1));
            i := i + 1;
          end;
      end;
    if pos(Delimit, aux) <> 0 then
      aux := Copy(aux, 0, pos(Delimit, aux) - 1);
    Result := aux;
  end;


Saludos.