Replace token with another WPRichText content

  • Hi,

    I have an instance of WPRichText with this:

    "My name is <name>"

    I want to replace "<name>" with the content of another WPRichText, so I did:

    WPRichText1.Finder.ReplaceAll("<name>",WPRichText2.AsString);

    The thing is, the replaced text apears as:

    {\rtf1\ansi\deff0\uc1\ansicpg1252\deftab720{\fonttbl{\f0\fnil\fcharset1 Arial;}{\f1\fnil\fcharset2 Wingdings;}{\f2\fnil\fcharset2 Symbol;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;\red128\green128\blue0;}\wpprheadfoot1\paperw12240\paperh20160\margl567\margr740\margt1167\margb2830\headery254\footery254\endnhere\sectdefaultcl{\

    If I do:

    WPRichText1.Finder.ReplaceAll("<name>",WPRichText2.Text);

    Then its OK, but I loose the formatting I had in WPRichText2.

    I tried with Finder using Finder.FoundText but it happens the same thing.

    So I ask, How do I replace the token <name> in WPRichText1 with the content of another WPRichText without loose the text format and without have this RTF code?

    Thanks

  • Zitat von wpsupport

    Hi,

    ReplaceAll does not "load" text, si it does not interpret RTF.

    You do this:

    while Finder.Next ... do
    begin
    Finder.SelectText;
    SelectionAsString := rtfcode
    end;

    It worked, thanks Julian, I mp'ed you.

  • Strange, I have a very similar problem.

    If I use

    Code
    WPRichText1.Finder.ToStart;     WPRichText1.Finder.ReplaceAll('xxxx', 'yyyy');     WPRichText1.ReformatAll(True, True);

    then it works. Unfortunately I can't use that approach. I need to evaluate tags and replace them intelligently.
    (A tag would look like this: {V Params})

    So I tried

    and this doesn't work, no matter which insertion method I choose. The formatting of the paragraph is always lost for the inserted text.

    HELP!
    Thanks!