Ir para conteúdo
Fórum Script Brasil
  • 0

[Dúvida] FindReplace


LorenaMorena

Pergunta

Boa Tarde a todos!

Primeiramente, sou iniciante..

Bom , estou fazendo um progama , que esta ficando show de bola galera..

este progama tem a função de trocar as strings de uma lista , de um arquivo de texto..

Estou atualmente usando a seguinte função para trocar strings em um RichEdit...

// Faz a procura e substitui uma String no campo memo.
// Exemplo :: FindReplace(Edit1.Text,Edit2.Text, Memo1);
Procedure FindReplace (const Enc, subs: String; Var Texto: TRichEdit);
Var
i, Posicao: Integer;
Linha: string;

Begin

  For i := 0 to Texto.Lines.count - 1 do
    begin
      Linha := Texto. Lines[i];
    Repeat
    Posicao:=Pos(Enc,Linha);
      If Posicao > 0 then      //se encontra palavra
        Begin
            Delete(Linha,Posicao,Length(Enc)); //deleta
            Insert(Subs,Linha,Posicao);
            Texto.Lines[i] := Linha;
        end;
    until Posicao = 0;
  end;
end;
ai na hora de trocar eu faço assim!:
FindReplace(ListBox1.Items.Strings[i],Listbox2.Items.Strings[i],richedit1); //TROCA STRING

Resumo do meu progama: 2 listbox, o 1º serve para add str, o 2º serve para confirmar só e ilustrar xDDD!

Ok! Atualmente funciona perfeitamente!!

ele pega do primeiro Listbox1 e trocar pelo Listbox2 as strings...

Mas eu queria apenas mais uma coisinha nesta função que é meu motivo de vinda até aqui!!!

Sabe a opção frWholeWord e a opção frMatchCase?

Então , gostaria de implementar essas 2 funçãozinhas no meu procedimento de alterar string!!!

Mas infelizmente não estou conseguindo . Será q alguém pode me enviar um dica?

Muito Obrigado , tenha um bom dia!

Link para o comentário
Compartilhar em outros sites

7 respostass a esta questão

Posts Recomendados

  • 0
Mas eu queria apenas mais uma coisinha nesta função que é meu motivo de vinda até aqui!!!

Sabe a opção frWholeWord e a opção frMatchCase?

Então , gostaria de implementar essas 2 funçãozinhas no meu procedimento de alterar string!!!

Mas infelizmente não estou conseguindo . Será q alguém pode me enviar um dica?

Seria algo parecido com isto, entretanto a implementação do código é por sua conta

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    FindDialog1: TFindDialog;
    ReplaceDialog1: TReplaceDialog;
    procedure ReplaceDialog1Replace(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure DoMatchCase(Procurar, Trocar : string);
begin
// frMatchCase    This flag is turned on (off) when the user selects (deselects) the Match Case check box. To select the check box by default when the dialog opens, set frMatchCase at design time.

end;

procedure DoWholeWord(Procurar, Trocar : string);
begin
// frWholeWord    This flag is turned on (off) when the user selects (deselects) the Match Whole Word check box. To select the check box by default when the dialog opens, set frWholeWord at design time.

end;

procedure TForm1.ReplaceDialog1Replace(Sender: TObject);
begin
  with Sender as TReplaceDialog do
  begin
  if frMatchCase in Options then
     DoMatchCase(FindText, ReplaceText)
  else
     if frWholeWord in Options then
        DoWholeWord(FindText, ReplaceText);
  end;
end;

end.

OBS: Para te ajudar um pouco sobre o assunto veja este post

http://scriptbrasil.com.br/forum/index.php...st&p=473652

abraço

Link para o comentário
Compartilhar em outros sites

  • 0

Mais uma dica pra voce

unit   Search;   
    
    
  interface   
  uses   WinProcs,   SysUtils,   StdCtrls,   Dialogs;   
  const   
        WordDelimiters:   set   of   Char   =   [#0..#255]   -   ['a'..'z','A'..'Z','1'..'9','0'];   
  function   SearchMemo(Memo:   TCustomEdit;   
                  const   SearchString:   String;Options:   TFindOptions):   Boolean;   
  function   SearchBuf(Buf:   PChar;   BufLen:   Integer;SelStart,   SelLength:   Integer;   
                  SearchString:   String;Options:   TFindOptions):   PChar;   
    
  implementation   
    
  function   SearchMemo(Memo:   TCustomEdit;const   SearchString:   String;   
                                                                                      Options:   TFindOptions):   Boolean;   
  var   
      Buffer,   P:   PChar;   
      Size:   Word;   
  begin   
      Result   :=   False;   
      if   (Length(SearchString)   =   0)   then   Exit;   
      Size   :=   Memo.GetTextLen;   
      if   (Size   =   0)   then   Exit;   
      Buffer   :=   StrAlloc(Size   +   1);   
      try   
            Memo.GetTextBuf(Buffer,   Size   +   1);   
            P   :=   SearchBuf(Buffer,   Size,   Memo.SelStart,Memo.SelLength,SearchString,   Options);   
            if   P   <>   nil   then   
            begin   
                Memo.SelStart   :=   P   -   Buffer;   
                Memo.SelLength   :=   Length(SearchString);   
                Result   :=   True;   
            end;   
      finally   
            StrDispose(Buffer);   
      end;   
  end;   
    
  function   SearchBuf(Buf:   PChar;   BufLen:   Integer;SelStart,   SelLength:   Integer;   
          SearchString:   String;Options:   TFindOptions):   PChar;   
  var   
      SearchCount,   I:   Integer;   
      C:   Char;   
      Direction:   Shortint;   
      CharMap:   array   [Char]   of   Char;   
    
  function   FindNextWordStart(var   BufPtr:   PChar):   Boolean;   
  begin   {   (True   XOR   N)   is   equivalent   to   (not   N)   }   
    //   Result   :=   False;   {   (False   XOR   N)   is   equivalent   to   (N)   }   
      {   When   Direction   is   forward   (1),   skip   nondelimiters,   then   skip   delimiters.   }   
      {   When   Direction   is   backward   (-1),   skip   delims,   then   skip   non   delims   }   
      while   (SearchCount   >   0)   and   ((Direction   =   1)   xor   (BufPtr^   in   WordDelimiters))   do   
      begin   
          Inc(BufPtr,   Direction);   
          Dec(SearchCount);   
      end;   
      while   (SearchCount   >   0)   and   ((Direction   =   -1)   xor   (BufPtr^   in   WordDelimiters))   do   
      begin   
          Inc(BufPtr,   Direction);   
          Dec(SearchCount);   
      end;   
      Result   :=   SearchCount   >   0;   
      if   Direction   =   -1   then   
      begin   {   back   up   one   char,   to   leave   ptr   on   first   nondelim   }   
          Dec(BufPtr,   Direction);   
          Inc(SearchCount);   
      end;   
  end;   
    
  begin   
      Result   :=   nil;   
      if   BufLen   <=   0   then   Exit;   
      if   frDown   in   Options   then   
      begin   
          Direction   :=   1;   
          Inc(SelStart,   SelLength);   {   start   search   past   end   of   selection   }   
          SearchCount   :=   BufLen   -   SelStart   -   Length(SearchString);   
          if   SearchCount   <   0   then   Exit;   
          if   Longint(SelStart)   +   SearchCount   >   BufLen   then   
                Exit;   
      end   else   
      begin   
          Direction   :=   -1;   
          Dec(SelStart,   Length(SearchString));   
          SearchCount   :=   SelStart;   
      end;   
      if   (SelStart   <   0)   or   (SelStart   >   BufLen)   then   Exit;   
      Result   :=   @Buf[SelStart];   
      {   Using   a   Char   map   array   is   faster   than   calling   AnsiUpper   on   every   character   }   
      for   C   :=   Low(CharMap)   to   High(CharMap)   do   
            CharMap[C]   :=   C;   
      if   not   (frMatchCase   in   Options)   then   
      begin   
          AnsiUpperBuff(PChar(@CharMap),   sizeof(CharMap));   
          AnsiUpperBuff(@SearchString[1],Length(SearchString));   
      end;   
      while   SearchCount   >   0   do   
      begin   
          if   frWholeWord   in   Options   then   
              if   not   FindNextWordStart(Result)   then   Break;   
              I   :=   0;   
              while   (CharMap[Result[I]]   =   SearchString[I+1])   do   
              begin   
                  Inc(I);   
                  if   I   >=   Length(SearchString)   then   
                  begin   
                      if   (not   (frWholeWord   in   Options))   or   (SearchCount   =   0)   or   
                          (Result[I]   in   WordDelimiters)   then   
                                Exit;   
                      Break;   
                  end;   
              end;   
              Inc(Result,   Direction);   
              Dec(SearchCount);   
      end;   
      Result   :=   nil;   
  end;   
    
  end.
Veja se consegue implementar o que falta ao seu programa abraço Vou te passar um programa completo ( NOTEPAD EM DELPHI )
program Notepad;

uses 
 Forms, 
 UnitMain in 'UnitMain.pas'{FormMain},
 Unit1 in 'Unit1.pas'{AboutBox}; 

 {$R *.RES} 

 begin 
 Application.Initialize; 
 Application.CreateForm(TFormMain, FormMain);
 Application.CreateForm(TAboutBox, AboutBox); 
 Application.Run; 
 end. 

unit UnitMain; 

interface

uses 
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
 Dialogs, Menus, StdCtrls, ComCtrls; 
  
type 
 TFormMain = class(TForm1)
 RichEdit1: TRichEdit; 
 MainMenu1: TMainMenu; 
 MenuFile: TMenuItem; 
 ItemNew: TMenuItem; 
 ItemOpen: TMenuItem; 
 ItemSave: TMenuItem; 
 ItemSaveAs: TMenuItem;

 N2: TMenuItem; 
 ItemPrint: TMenuItem; 
 N4: TMenuItem; 
 ItemClose: TMenuItem; 
 SaveDialog1: TSaveDialog;
 OpenDialog1: TOpenDialog; 
 N1: TMenuItem; 
 ItemFont: TMenuItem; 
 FontDialog1: TFontDialog; 
 PopupMenu1:TPopupMenu; 
 ItemUndo: TMenuItem;
 N3: TMenuItem; 
 ItemRedo: TMenuItem; 
 ItemCut: TMenuItem; 
 ItemCopy: TMenuItem; 
 ItemPaste: TMenuItem; 
 ItemDelete: TMenuItem;
 N5: TMenuItem; 
 ItemSelectAll:TMenuItem; 
 N6: TMenuItem; 
 ItemFindText: TMenuItem; 
 ItemFindAndReplace: TMenuItem; 
 FindDialog1: TFindDialog;
 MenuEdit: TMenuItem; 
 ItemUndo1:TMenuItem; 
 ItemRedo1: TMenuItem; 
 N7: TMenuItem; 
 ItemCut1: TMenuItem; 
 ItemCopy1: TMenuItem;
 ItemPaste1: TMenuItem; 
 ItemDelete1: TMenuItem; 
 N8: TMenuItem; 
 ItemSelectAll1: TMenuItem; 
 N9: TMenuItem; 
 ItemFind1: TMenuItem; 
 ItemFindAndPlace1: TMenuItem;
 N10: TMenuItem; 
 ItemAutoWarp1: TMenuItem; 
 N11: TMenuItem; 
 ItemAutoWarp: TMenuItem; 
 ReplaceDialog1: TReplaceDialog; 
 N12: TMenuItem; 
 N13: TMenuItem;
 N14: TMenuItem; 
 procedure ItemNewClick(Sender: Tobject); 
 procedure ItemOpenClick(Sender: Tobject); 
 procedure ItemSaveClick(Sender: Tobject); 
 procedure ItemPrintClick(Sender: Tobject); 
 procedure ItemCloseClick(Sender: Tobject); 
 procedure ItemFondClick(Sender: Tobject);
 procedure PopupMenu1Popup(Sender: Tobject); 
 procedure ItemUndoClick(Sender: Tobject); 
 procedure ItemRedoClick(Sender: Tobject); 
 procedure ItemCutClick(Sender: Tobject); 
 procedure ItemCopyClick(Sender: Tobject); 
 procedure ItemPasteClick(Sender: Tobject); 
 procedure ItemDelectClick(Sender: Tobject);
 procedure ItemSelectClick(Sender: Tobject); 
 procedure ItemFindTextClick(Sender: Tobject); 
 procedure FindDialog1Find(Sender: Tobject); 
 procedure ItemAutoWarp1Click(Sender: Tobject); 
 procedure ItemFindAndReplaceClick(Sender: Tobject); 
 procedure ReplaceDialog1Replace(Sender: Tobject);
 procedure FormCreat(Sender: Tobject); 
 procedure MenuFileClick(Sender: Tobject); 
 procedure FromCloseQuery(Sender: Tobject; var CanClose: Boolean); 
 procedure N14Click(Sender: Tobject); 
 private 
 sFileName:String;
 Function CheckhasModified:Boolean;
 Function SaveAsFile:Boolean;
 Function SaveFile:Boolean;
 Function MyOpenFile(FileName:String):Boolean;
 { Private declarations } 
 public
 { Public declarations } 
 end; 

var 
 FormMain: TFormMain; 

implementation 

uses RichEdit,Unit1; 

{$R *.dfm} 

function TFormMain.CheckHasModified: Boolean;
begin 
 Result:=not RichEdit1.Modified; 
 if not Result then 
 begin 
 Case Application.MessageBox('??????!??????','??',
 MB_YESNO+mB_ICONQUESTION) OF 
 IDYES:Result:=SaveFile; 
 IDNO:Result:=True; 
 end; 
 end; 
end;

 procedure TFormMain.ItemNewClick(Sender: TObject); 
 begin
 If CheckHasModified Then 
 begin 
 RichEdit1.Lines.Clear;
 RichEdit1.Modified:=False; 
 sFileName:='???'; 
 end; 
end;

function TformMain.SaveAsFile:Boolean;
begin
 Result:=False; 
 if SaveDialog1.Execute then 
 begin 
 RichEdit1.Lines.SaveToFile(SaveDialog1.FileName0; 
 RichEdit1.Modified:=False;
 sFileName:=SaveDialog1.FileName; 
 Result:=True; 
 end; 
end;

procedure TFormMain.ItemOpenClick(Sender: TObject);
begin
 if OpenDialog1.Execute then 
 MyOpenFile(OpenDialog1.FileName); 
end;

Procedure TFormMain.ItemSaveClick(Sender: TObject);
begin
 SaveFile; 
end; 

function TFormMain.SaveFile: Boolean; 
begin
 If sFileName='???' then 
 Result:=SaveAsFile 
 else 
 begin 
 RichEdit1.Lines.SaveToFile(sFileName); 
 RichEdit1.Modified:=False;
 Result:=True; 
 end; 
end;

 procedure TFormMain.ItemSaveAsClick(Sender:TObject); 
 begin
 SaveAsFile;
 end; 

 procedure TFormMain.ItemPrintClick(Sender:TObject); 
 begin
 RichEdit1.Print(sFileName);
 end; 

 procedure TFormMain.ItemCloseClick(Sender: TObject); 
 begin
 Close; 
 end;

 procedure TFormMain.ItemFontClick(Sender: TObject); 
 begin
 FontDialog1.Font.Assign(RichEdit1.Font); 
 if FontDialog1.Execute then 
 RichEdit1.Font.Assign(FontDialog1.Font);
 end; 

 procedure TFormMain.PopupMenu1Popup(Sender: TObject); 
 begin
 ItemUndo.Enabled:=(RichEdit1.Perform(EM_CANUNDO,0,0<>0); 
 ItemRedo.Enabled:=(RichEdit1.Perform(EM_CANREDO,0,0<>0);
 ItemCut.Enabled:=(RichEdit1.Perform(EM_SELECTIONTYPE,0,0)<>0); 
 ItemCopy.Enabled:=ItemCut.Enabled; 
 ItemPaste.Enabled:=(RichEdit1.Perform(EM_CANPASTE,0,0)<>0); 
 ItemAutoWarp.Checked:=RichEdit1.WordWrap; 
 ItemUndo1.Enabled:=(RichEdit1.Perform(EM_CANUNDO,0,0<>0); 
 ItemRedo1.Enabled:=(RichEdit1.Perform(EM_CANREDO,0,0<>0);
 ItemCut1.Enabled:=(RichEdit1.Perform(EM_SELECTIONTYPE,0,0)<>0); 
 ItemCopy1.Enabled:=ItemCut.Enabled; 
 ItemPaste1.Enabled:=(RichEdit1.Perform(EM_CANPASTE,0,0)<>0); 
 ItemAutoWarp1.Checked:=RichEdit1.WordWrap; 
 end; 

 procedure TFormMain.ItemUndoClick(Sender: TObject); 
 begin
 RichEdit1.Perform(EM_UNDO,0,0); 
 end; 

 procedure TFormMain.ItemRedoClick(Sender:TObject);
 begin
 RichEdit1.Perform(EM_REDO,0,0); 
 end; 

 procedure TFormMain.ItemCutClick(Sender: TObject); 
 begin
 RichEdit1.Perform(WM_CUT,0,0); 
 end; 

 procedure TFormMain.ItemCopyClick(Sender:TObject); 
 begin
 RichEdit1.Perform(WM_COPY,0,0);
 end; 

 procedure TFormMain.ItemPasteClick(Sender:TObject); 
 begin
 RichEdit1.Perform(WM_Paste,0,0); 
 end;

 procedure TFormMain.ItemDeleteClick(Sender: TObject);
 begin
 RichEdit1.Perform(WM_CLEAR,0,0); 
 end; 

 procedure TFormMain.ItemSelectAllClick(Sender: TObject); 
 Var P:TPoint;
 begin 
 P:=Point(0,0); 
 P:=RichEdit1.ClientToScreen(P); 
 FindDialog1.Position := P;
 FindDialog1.Execute; 
 end; 

 procedure TFormMain.FindDialog1Find(Sender: TObject); 
 var
 FoundAt: LongInt;
 StartPos, ToEnd: Integer; 
 st:TSearchTypes; 
 begin 
 with RichEdit1 do 
 begin 
 StartPos :=SelStart + SelLength;
 ToEnd := Length(Richedit1.Text) - StartPos; 
 st:=[]; 
 if frMatchCase in FindDialog1.Options then 
 st:=st+[stMatchCase]; 
 if frWholeWord in FindDialog1.Options then 
 st:=st+[stWholeWord];
 FoundAt := FindText(FindDialog1.FindText,StartPos,Toend,st); 
 if FoundAt <> -1 then 
 begin 
 SelStart := FoundAt; 
 SelLength := Length(FindDialog1.FindText); 
 end else
 ShowMessage('????!') 
 end; 
 end; 

 procedure TFormMain.ItemAutoWarp1Click(Sender: TObject);
 begin
 RichEdit1.WordWrap:=not RichEdit1.WordWrap; 
 ItemAutoWarp1.Checked:=RichEdit1.WordWrap; 
 ItemAutoWarp.Checked:=RichEdit1.WordWrap; 
 end;

 Function TFormMain.MyOpenFile(FileName:String):Boolean; 
 begin
 Result:=False; 
 if CheckHasModified then
 begin 
 try 
 RichEdit1.Lines.LoadFromFile(FileName); 
 RichEdit1.Modified:=False 
 sFileName:=FileName;
 Result:=True; 
 except 
 on E:Exception do 
 ShowMessage(E.Message); 
 end;
 end; 
 end; 

 procedure TFormMain.ItemFindAndREplaceClick(Sender:TObject); 
 Var P:TPoint;
 begin 
 P:=Point(0,0); 
 P:=RichEdit1.ClientToScreen(P); 
 ReplaceDialog1.Position := P; 
 ReplaceDialog1.Execute;
 end; 

 procedure TFormMain.ReplaceDialog1Replace(Sender: TObject); 
 Var P:TPoint;
 begin
 P:=Point(0,0); 
 P:=RichEdit1.ClientToScreen(P); 
 ReplaceDialog1.Position := P; 
 ReplaceDialog1.Execute; 
 end;

 procedure TFormMain.ReplaceDialog1Replace(Sender: TObject): 
 var
 FoundAt: LongInt; 
 StartPos, ToEnd: Integer;
 st:TSearchTypes; 
 begin 
 with RichEdit1 do 
 begin 
 StartPos := SelStart + SelLength;
 ToEnd := Length(RichEdit1.Text) - StartPos; 
 st:=[]; 
 if frMatchCase in ReplaceDialog1.Options then 
 st:=st+[stMatchCase]; 
 if frWholeWord in ReplaceDialog1.Options.then
 st:=st+[stWholeWord]; 
 FoundAt := FindText(Replacedialog1.FindText, StartPos, ToEnd, st); 
 While FoundAt <> -1 do 
 begin 
 SelStart := FoundAt;
 SelLength := Length(ReplaceDialog1.FindText); 
 Perform(EM_REPLACESEL,1,Interger(PChar(Replacedialog1.ReplaceText))); 
 SelStart := FoundAt; 
 SelLength := Length(ReplaceDialog1.ReplaceText); 
 if not (frReplaceAll in ReplaceDialog1.Options) then
 Break; 
 StartPos:=SelStart; 
 ToEnd := Length(RichEdit1..Text) - StartPos; 
 FoundAt := FindText(ReplaceDialog1.FindText, StartPos,ToEnd,st); 
 end;
 FoundAt:= FindText(ReplaceDialog1.FindText,StartPos,ToEnd,st); 

 if FoundAt=-1 then
 ShowMessage('????!'); 
 end;
end;

 procedure TFormMain.FormCreate(Sender: TObject); 
 Var s1FileName,TemStr,ParamString:String;
 i,FromIndex,ToIndex,iPox:Integer;
 Reg:TRegistry; 
 begin 
 try 
 Reg:=TRegistry.Create;
 try 
 Reg.RootKey:=HKEY_CLASSES_ROOT; 
 Reg.OpenKey('*\shell\MyNotePad',True); 
 Reg.WriteString('','????????');
 Reg.CloseKey; 
 Reg.OpenKey('*\Shell\MyNotePad\Command',True); 
 Reg.WriteString('','"'+ParamStr(0)+'" "%1"'); 
 Reg.CloseKey;
 finally 
 Reg.Free; 
 end; 
 except
 end;
 if ParamCount>=1 then 
 begin 
 i:=1;
 ParamString:=ParamStr(i); 
 While (ParamString[1]='/') and(i<=ParamCount) do 
 begin 
 Inc(i);
 ParamString:=ParamStr(i); 
 end; 
 FromIndex:=i; 
 ParamString:=ParamStr(i);
 if ParamString[1]='/' then 
 Exit; 
 While i<=ParamCount do 
 begin
 if ParamString[1]='/' then 
 Break; 
 Inc(i); 
 ParamString:=ParamStr(i);
 end; 
 ToIndex:=i; 
 s1FileName:=GetCommandLine; 
 ParamString:=ParamStr(FromIndex);
 iPos:=Pos(ParamString,s1Filename); 
 TemStr:=ParamString; 
 Delete(s1Filename,1,iPos-1+length(TemStr));
 For i:=FromIndex+1 to ToIndex do 
 begin 
 ParamString:=ParamStr(i);
 iPos:=pos(ParamString,s1FileName); 
 TemStr:=TemStr+copy(s1FileName,1,iPos+length(ParamString)); 
 end;
 s1FileName:=TemStr; 
 MyOpenFile(s1FileName); 
 For i:=1 to ParamCount do
 begin 
 if (ParamStr(i)='/p') or(ParamStr(i)='/p' then 
 begin
 if Application.MessageBox('????','??',MB_YESNO+MB_ICONQUESTION) 
 =IDYes then 
 RichEdit1.Print(sFileName);
 Break; 
 end; 
 end
 end; 

end;

 procedure TFormMain.MenuFileClick(Sender: Tobject); 
 begin
 ItemSave.Enabled:=RichEdit1.Modified; 
 end;

 procedure TFormMain.FormCloseQuery(Sender: TObject; VAr CanClose:Boolean);
 begin
 CanClose:=not RichEdit1.Modified;
 if not CanClose then
 begin
 Case Application.MessageBox('??????!??????','??',
 MB_YESNOCANCEL+MB_ICONQUESTION) of
 IDYES:CanClose:=SaveFile;
 IDNo:CanClose:=True;
 end;
 end;
 end;

 procedure TFormMain.N14Click(Sender:TObject);
 begin
 AboutBox.showmodal;
 end;
end.

Neste voce vai encontrar as funções que esta procurando

abraço

Link para o comentário
Compartilhar em outros sites

  • 0

Olá amigão ..

Estou me matando aqui , como disse sou iniciante .

Porém se eu conseguir alguma coisa eu posto a solução para todos ok?

Estou desesperando!!

OBS: aceito mais ajudas ^^

Antes de você postar, tentei algo do tipo:

Procedure FindReplace (const Procura, Substitui: String; Var Texto: TRichEdit);
Var
i, Posicao: Integer;
TodasLinhas: string;

Begin     
  For i := 0 to Texto.Lines.count - 1 do
    begin
      TodasLinhas := Texto. Lines[i];
    Repeat
    Posicao:=Pos(Procura,TodasLinhas);
      If Posicao > 0 then      //se encontra palavra
        Begin
            if Length(Procura) <> Length(Procura)  then  //se o tamanho de caracteres for diferente do tamanho de caractere  do que eu to procurando...
              begin                                                        //mas não deu xD
              Exit;
              end
            else
            if Length(Procura) = Length(Procura)  then

            Delete(TodasLinhas,Posicao,Length(Procura)); //deleta o que ta procurando
            Insert(Substitui,TodasLinhas,Posicao);       //substitui na posicao da linha
            Texto.Lines[i] := TodasLinhas;
            end;
        //end;
    until Posicao = 0;
  end;
end;

Muito obrigado pelo seu breve retorno .

Abraço

Editado por LorenaMorena
Link para o comentário
Compartilhar em outros sites

  • 0

Deicha eu te pergutnar uma coisa, tem como ao invés de ficar procurando string por string no evento Onreplace para chamar a caixa para procurar strings, fazer um processo automatizado? para não presisar ficar procurando e digitando nenhuma string.. porque as strings já estao em um listbox ... to querendo automatizar o processo de troca de strings, mas só falta o whole words manow. vou ter que trocar meu modo de trocar strings e implementar este tfindreplace dialog só por causa disto...

disto o que ?

exemplo..

ESTE é O RICHEDIT

DosHeader :TImageDosHeader ;

IMAGINE O LISTBOX AO LADO:

COM ESTE UNICO ITEM

DosHeader <-- ESTA é A STRING QUE EU ESCOLHI PARA MODIFICAR NO RICH

Quando eu clico no botao de mudar string o que acontece?

isto:

STRINGMUDADA :TImageSTRINGMUDADA ;

REPARE O TIMAGE , POR ISSO EU QUERO WHOLEWORDS ..

Obrigado pela sua ajuda!

Desculpe pela ignorancia minha ^^

Link para o comentário
Compartilhar em outros sites

  • 0
tem como ao invés de ficar procurando string por string no evento Onreplace para chamar a caixa para procurar strings, fazer um processo automatizado? para não presisar ficar procurando e digitando nenhuma string.. porque as strings já estao em um listbox ... to querendo automatizar o processo de troca de strings, mas só falta o whole words manow

voce pode fazer um processo automatizado, ou seja, basta ter uma lista de strings que serão lidas dentro de um comando FOR usando o OnReplace.

Se voce pensar um pouquinho, bastará mudar alguma coisa no seu código para conseguir isto

abraço

Link para o comentário
Compartilhar em outros sites

  • 0
... to querendo automatizar o processo de troca de strings, mas só falta o whole words manow. vou ter que trocar meu modo de trocar strings e implementar este tfindreplace dialog só por causa disto...
Parafraseando o colega Jhonas, eu diria que se você usasse a pesquisa do forum poderia ter encontrado este meu post com a implementação dos eventos OnFind e OnReplace.

Voce vai precisar da metade final do procedimento para OnReplace, estando ele dentro de um For que varre sua lista (conforme já sugeriu o colega Jhonas).

Abraços

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...