Trim empty lines inside paragraph and validation of solution

  • I get XML-data in which I need to replace <Bold> elements with the corresponding attribute for bold and such. For this I do this:

    Code
    const  BOLD_ON_Token = '<Bold>';  ...  procedure ReplaceAttribute(aRichText: TWPRichText; aStartToken, aEndToken: string; aElement: TOneWrtStyle);  var    StartID, EndID: Integer;  begin    aRichText.Finder.ToStart;    while true do    begin      if not aRichText.Finder.Next(aStartToken) then        break;      StartID := aRichText.Finder.DropMarkerAtFoundPosition(1);      if not aRichText.Finder.Next(aEndToken) then        break;      EndID := aRichText.Finder.DropMarkerAtFoundPosition(0);      if (StartID <> 0) and (EndID <> 0) then      begin        aRichText.TextCursor.SelectMarker(StartID, EndID);        try          aRichText.TextCursor.SelectedTextAttr.IncludeStyle(aElement);        finally          aRichText.TextCursor.CollectAllMarker;        end;      end;    end;  end;

    Is this a correct procedure?

    Later I remove the elements, using this (don't use wildcards);

    Code
    rtMessage.Finder.ToStart;
        rtMessage.Finder.ReplaceAll(ITALIC_ON_Token,'');
        rtMessage.Finder.ToStart;
        rtMessage.Finder.ReplaceAll(ITALIC_OFF_Token,'');
        rtMessage.Finder.ToStart;
        rtMessage.Finder.ReplaceAll(BOLD_ON_Token,'');
        rtMessage.Finder.ToStart;
        rtMessage.Finder.ReplaceAll(BOLD_OFF_Token,'');
        rtMessage.Finder.ToStart;
        ...

    When I preview the text, things look fine, but when I save to file and open in Word, the elements are still here. Wrong procedure?

    In the XML I would like to trim multiple newlines inside the text (in RTF they appear /line/lineCrLf/line/line/line.., where Cr = ascii 13 and Lf = ascii 10) and leave just one or two. Can anyone help me with a solution?

    Thanks in advance.[/code]

  • The XML I'm converting looks like this:

    Code
    - <Text01>  Best regards   <Break />   <bold>Dr. Suess</bold>   <Break />   15.01.2004.   <Break />   <Break />   <Break />   <Break />   <Break />   <Break />   </Text01>


    In RTF this ends up looking like this:

    Code
    Best regards
    \line <bold>Dr. Suess</bold>
    \line 15.01.2004.
    \line\line 
    \line\line 
    \line\line 
    \line\line 
    \line\line


    To many /line/line's. I would like to reduce that to just two newlines.

    The added spaces in the end of each line is something I also would like to remove. Adding (yet another) ReplaceAll with #32#13#10 replaced with #13#10 is fruitless, nothing happens.