Ver Mensaje Individual
  #2  
Antiguo 20-10-2007
Avatar de aeff
aeff aeff is offline
Miembro
 
Registrado: oct 2006
Ubicación: Cuba, Guantánamo
Posts: 348
Reputación: 18
aeff Va camino a la fama
implementa estas dos funciones y la variable siguiente:

Código Delphi [-]
var
  vContenido: string;

implementation

procedure LoadFileTxt(fname: string);
var
  vTxtFile: TextFile;
  vLine: string;
begin
  vContenido := '';
  AssignFile(vTxtFile, fname);
  Reset(vTxtFile);
  while not Eof(vTxtFile) do
    begin
      Read(vTxtFile, vLine);
      vContenido := vContenido + vLine + ' ';
    end;
  CloseFile(vTxtFile);
end;

function GetPalabra(index: Integer): string;
var
  vSubStr, vWord: string;
  WordCount: Integer;
begin
  WordCount := 0;
  vSubStr := TRIM(vContenido) + ' ';
  while WordCount < index do
    begin
      if vSubStr = ' ' then
        begin
          vWord := '';
          break;
        end;
      vWord := Copy(vSubStr, 1, Pos(' ', vSubStr));
      vSubStr := TRIM( Copy(vSubStr, Length(vWord), Length(vSubStr))) + ' ';
      Inc(WordCount);
    end;
  Result := vWord;
end;

un ejemplo de uso:

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
  LoadFileTxt('C:\aeff.txt');
  Caption := GetPalabra(3);
end;

espero que te sirva,

saludos

aeff
Responder Con Cita