Delete carriage return

  • I want to delete the carriage return if the word I'm searching is alone on the line.
    I'm doing that this way :
    (wpDoc is a TWPRichText)


    I use a button to launch the function.

    The function works perfectly when I click on the button immediately after loading the RTF File in the editor, but when I click on the TWPRichText before launching the function, it deletes more text than needed.

    Do I use the right way to do what I want to do? Is there any better solution?
    Why doesn't the function work every time I try it?

    I need help please.
    Thanks.

    • Offizieller Beitrag

    Hi,

    for something like this please use the low level methods:

    Code
    par := WPRichText1.FirstPar;
      while(par<>nil) do
      begin
         if par.ANSIText= 'test' then
            par := par.DeleteParagraph
         else par := par.NextPar;
      end;
      WPRichText1.ReformatAll(false, true);

    The TParagraph object also has the function "HasText" which may come usefull.

    Julian

  • It works fine with:

    Code
    par := WPRichText1.FirstPar;
    while(par<>nil) do
      begin
         if par.ANSIText= 'test' then
            par := par.DeleteParagraphEnd;
            par := par.NextPar;
         else par := par.NextPar;
      end;
    WPRichText1.ReformatAll(false, true);


    Thanks!