Insert a string using "SelectionAsString" function

  • Hello,

    I have some problems with the "SelectionAsString" function.

    I have two merge fields like that:
    <<Mergefield_1>>
    <<Mergefield_2>>

    What I try to do is to put my cursor in the right place to add text between the 2 merge fields.

    Code
    pwptDoc->SelStart = 14; (end of the first merge field)
    pwptDoc->SelLength = 0;
    pwptDoc->CPPosition = 14;
    pwptDoc->SelectionAsString = "myString";

    But by doing this, it deletes me the "<<" of the second merge field, which isn't recognize as a merge field anymore.
    (I've already tried just with "pwptDoc->SelectionAsString = "myString";" but it didn't work neither).

    I have noticed that when I'm at the end of the first line and try to select the next character with "Shift+ Right Arrow", it selects the whole second merge field.
    But when I delete the same character I've tried to select before (with the "Del" key), it deletes me the carriage return. Maybe it has something to do with my problem.

    Can you tell me if it's normal? How can I fix my problem?

    Thanks,

    Claire.

    • Offizieller Beitrag

    Hi,

    Please do not move the cursor with SelStart - just do a CPPosition.

    How did you get the 14? If this are merge fields you can move right after the closing field, marked by the >> sign.

    You can use FindField and use

    TextCursor.CPObj := Mergefiled.EndTag; // Move before the end tag
    CPMoveNext; // to skip it.

    Julian