Foro de elhacker.net

Programación => Programación General => Mensaje iniciado por: Psyke1 en 23 Agosto 2010, 18:37 pm



Título: [SRC] [Delphi] Text_Beetwen_Words [by *PsYkE1*]
Publicado por: Psyke1 en 23 Agosto 2010, 18:37 pm
Hola, me he pasado a Delphi hace dos dias y he pasado esta funcion que tenia hecha en VB6...  :P

http://foro.rthacker.net/programacion-visual-basic/%28src%29-%28funcion%29-text_between_words-%28by-*psyke1*%29/

Código
  1. (* * * * * * * * * * * * * * * * * * * * * * * * * *)
  2. (* Function : Text_Beetwen_Words                   *)
  3. (* Author   : *PsYkE1*                             *)
  4. (* Mail     : vbpsyke1@mixmail.com                 *)
  5. (* Date     : 24/8/10                              *)
  6. (* Purpose  : Returns text which is beetwen        *)
  7. (*            two words.                           *)
  8. (* Visit    : http://foro.rthacker.net/            *)
  9. (* * * * * * * * * * * * * * * * * * * * * * * * * *)
  10.  
  11. function InStr(iStart: integer; sText: string; sWord: string): integer;
  12. begin
  13. Result := Pos(sWord,Copy(sText,iStart,Length(sText) - (iStart - 1)));
  14. end;
  15.  
  16. function Text_Beetwen_Words(sTextToAnalyze:String ; sStartWord:String ; sEndWord:string): String;
  17. var
  18.  iPosition1  : Integer;
  19.  iPosition2  : Integer;
  20.  iStart      : Integer;
  21. begin
  22.     iPosition1 := Instr(1,sTextToAnalyze,sStartWord);
  23.     if iPosition1 > 0 then
  24.      begin
  25.        iStart := (iPosition1 + Length(sStartWord));
  26.        iPosition2 := Instr(iStart,sTextToAnalyze,sEndWord);
  27.      end
  28.     else
  29.      exit;
  30.     if iPosition2 > 0 then
  31.      Result := Copy(sTextToAnalyze,iStart,iPosition2 -1);
  32. end;

Un ejemplo:
Código
  1. procedure TForm1.FormCreate(Sender: TObject);
  2.    begin
  3.      (* añade un textbox *)
  4.    edit1.Text:= text_beetwen_words('Hoy estoy muy aburrido','Hoy ',' aburrido');
  5.    end;
  6.  
  7. end.

Devuelve esto:
Citar
estoy muy

DoEvents¡! :P


Título: Re: [Delphi] Text_Beetwen_Words [by *PsYkE1*]
Publicado por: VanHan en 24 Agosto 2010, 02:23 am
Me encanto  ;D Lindo Source

Salu2
[vHn]


Título: Re: [Delphi] Text_Beetwen_Words [by *PsYkE1*]
Publicado por: Psyke1 en 24 Agosto 2010, 02:40 am
Gracias, ire pasando mis funciones de vb a delphi progresivamente...

DoEvents¡! :P