TransWikia.com

How do I replace characters from dynamic variables in a loop?

Salesforce Asked by B Elliott on January 18, 2021

I am trying to replace multiple special characters from dynamic variable in loop of products (set @product1 = Name® of Product One™, @product2 = Name® of Product Two™, @product3 = Name® of Product Three™, etc.) This is a simplified example – The following code replaced no characters:

%%[
        set @myCount = 0
        %%[ FOR @myCount = 1 TO @numVars DO ]%%
        %%[
                set @prod = Concat('%%=v(@product',@myCount,')=%%')
                set @prodA = Replace(@prod, "®", "<sup style='font-size:9px;font-weight:normal;'>&reg;</sup>")
                set @prodB = Replace(@prodA, "™", "<sup style='font-size:11px;font-weight:normal'>&trade;</sup>")
                set @productTitle = Replace(@prodB, "Bluetooth", "<i>Bluetooth</i>")
        ]%%
            <p>%%=TreatAsContent(@productTitle)=%%</p>
        %%[ NEXT ]%%
]%%

I have tried multiple variations and cannot get the characters to replace. Can anyone help?

One Answer

Resolved. Revised code is working:

%%[
    set @myCount = 0
    %%[ FOR @myCount = 1 TO @numVars DO ]%%
    %%[
            set @prod = Concat('%%=v(@product',@myCount,')=%%')
            set @prodA = Replace(TreatAsContent(@prod), "®", "<sup style='font-size:9px;font-weight:normal;'>&reg;</sup>")
            set @prodB = Replace(TreatAsContent(@prodA), "™", "<sup style='font-size:11px;font-weight:normal'>&trade;</sup>")
            set @productTitle = Replace(TreatAsContent(@prodB), "Bluetooth", "<i>Bluetooth</i>")
    ]%%
        <p>%%=TreatAsContent(@productTitle)=%%</p>
    %%[ NEXT ]%%

]%%

Answered by B Elliott on January 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP