sSplitDirigido [By Expermicid]

Iniciado por Expermicid, Julio 09, 2012, 05:34:26 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Julio 09, 2012, 05:34:26 PM Ultima modificación: Abril 21, 2013, 01:10:21 PM por Expermicid
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. :)



Código: delphi
//  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.