Hi @Newbie2019 ,
I hope I'm understanding this correctly, otherwise I'm solving a different problem 😊
The idea would be to collect selected sentences that already have ^ placeholders in them into a paragraph, then replace the ^ iteratively with FirstN/PN in an alternating pattern throughout the paragraph - is that right?
This may or may not be easy, depending on how strict your rules are around the construction of the sentences - more specifically the placing of FirstN, or PN. What I mean is, ^ is a single character. You can't just tell by looking at a sentence whether ^ should be FirstN or PN.
If you have control over the sentences, you might want to consider making your life a little easier and using a ^ for FirstN and something like a # for PN - that way you can do a simple substitution, but if you don't have this control and you're stuck with ^ placeholders, then you need to rely on your rule.
If your rule is that they will always alternate, (FirstN/PN/FirstN/PN) then it's doable with just a ^ placeholder.
I took a stab at the code out of interest - if I missed the boat on your question maybe it will help someone else 😉
Someone better than me can probably also tidy it up a bit or shorten it - eg: you can just use one collection for the paragraph, where I used first a variable and then a collection - but that was mainly to avoid First(collection).value statements messing up the code or just plain confusing me 😊
To test, stick this code on a button OnSelect: property and put a label on the page, setting it's Text: property to outputSentence to see the result when you press the button;
UpdateContext({varParagraph: "^ has worked well and continues to improve. ^ has limited knowledge of quantum mechanics; however, does have a solid understanding of orbital theory. It is expected that with significant support ^ will develop the required skills.", FirstN: "Bob", PN: "He"}); //sets up the sentence and FirstN/PN vars
ClearCollect(CollectPlaceholders,
AddColumns(Split(varParagraph, "^"),
"Index", 0,
"Alt", "placeholder"
)
); //sets up a collection that splits out the paragraph wherever ^ appears
UpdateIf(CollectPlaceholders, Index=0, {
Index: Last(SortByColumns(CollectPlaceholders, "Index", Ascending)).Index + 1
}); //sets up an index for each instance of the ^ - now we know how many there are
UpdateIf(CollectPlaceholders, Alt="placeholder", {
Alt: If(Mod(Index, 2)=1, FirstN, PN)
}); //alternately sets each instance of ^ to FirstN if the index is odd, or PN if its even
ClearCollect(collectParser, {outcome: varParagraph}); //puts our sentence into a new collection, just to keep it clean for now - can consolidate later if needed
ForAll(CollectPlaceholders As currentRecords,
Collect(collectParser, {outcome:
Substitute(
Last(collectParser).outcome, "^", currentRecords.Alt, 1
)
})
); //for each split instance of ^, substitute only the first ^ in the original sentence with the instance alt. (once it's substituted and runs to the next "instance of ^" it will substitute the next "first" one - thereby working through the sentence until all ^'s are replaced
Set(outputSentence, Last(collectParser).outcome) //updates our output var so we can see the result
Should be enough there for you to pull apart and repackage how you need it - assuming again I understood your question correctly 😁
If your rule isn't "alternating" then perhaps some clarification?
Otherwise I hope this helps,
RT