Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 22-02-2015
JuanOrtega JuanOrtega is offline
Miembro
NULL
 
Registrado: sep 2011
Posts: 130
Poder: 13
JuanOrtega Va por buen camino
Funcion para extraer texto de archivos de texto

Hola tengo el siguiente codigo :

Código Delphi [-]

function read_file(const FileName: String): AnsiString;
var
  Stream: TFileStream;
begin
  Stream := TFileStream.Create(FileName, fmOpenRead);
  try
    SetLength(Result, Stream.Size);
    Stream.ReadBuffer(Pointer(Result)^, Stream.Size);
  finally
    Stream.Free;
  end;
end;

function cortar(archivo: String; deaca: String; hastaaca: String): String;
var text:string;
begin
  text := read_file(archivo);
  Delete(text, 1, AnsiPos(deaca, text) + Length(deaca) - 1);
  SetLength(text, AnsiPos(hastaaca, text) - 1);
  Result := text;
end;

function cut(archivo,Delimit1, Delimit2 :String) :String;
var
  Buffer      :AnsiString;
  ResLength   :Integer;
  i           :Integer;
  PosDelimit  :Integer;
begin
  Buffer := read_file(archivo);
  if Pos(Delimit1, Buffer) > Pos(Delimit2, Buffer) then
    PosDelimit := Length(Buffer)-(Pos(Delimit1, Buffer)+Length(Delimit1))
  else PosDelimit := Length(Buffer)-(Pos(Delimit2, Buffer)+Length(Delimit2));
  Buffer := Copy(Buffer, (Length(Buffer)-PosDelimit), Length(Buffer));
  ResLength := Pos(Delimit2, Buffer)-(Pos(Delimit1, Buffer)+Length(Delimit1));
  for i := 0 to (Reslength-1) do
    Result := Result+Buffer[Pos(Delimit1, Buffer)+(Length(Delimit1)+i)];
end;

Estoy tratando de mejorar mi funcion cortar() para que se parezca mas a la funcion cut() del codigo mostrado , lo que hacen es leer un archivo cualquiera y buscar en ellos texto que este entre dos etiquetas , el problema es que mi funcion cortar() me parece perfecta pero nunca obtengo el mismo resultado que la funcion cut() que parece mas compleja y no entiendo cual es el diferencia entre las dos porque cuando uso texto normal en un string las dos funciones son iguales pero cuando leo un archivo la funcion cut() es notablemente superior.

¿ como mejoro mi funcion cortar() para que haga lo mismo que cut() en los archivos ?
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Leer Archivos *.kar y desplegar su texto para Karaoke cacuna Varios 8 14-10-2010 14:34:04
¿Hay alguna función ya hecha para comprobar si un texto se puede convertir a número? noob Varios 7 05-12-2008 01:44:24
Wizard para importacion archivos texto GuerreroDelphi OOP 1 25-08-2008 15:25:49
Funciòn para extraer un campo texto zvf SQL 9 07-12-2007 21:32:03
Leer varios archivos de texto y extraer solo 2 lineas de ese texto mp3968 Internet 1 17-05-2007 20:24:09


La franja horaria es GMT +2. Ahora son las 19:31:26.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi