How to access Key & Values individually and not in for loop from dictionary

Hi @balupad14 @vvaidya @ddpadil
I have a dictionary named as “dict1” with below key value pair
Key Value
{First Name} argument_FirstName
{Last Name} argument_LastName
{FullName} argument_FullName
{Age} argument_Age

Now i need to replace key with values in the word template wherever this key(dynamic field) is present then it should replace to their corresponding values
so it should look like this:
for example
argument_FirstName is Vikrant
then the dynamic field -{First Name} should be replaced to Vikrant

is it possible accomplish this ?

TIA
Regards

1 Like

Hi there,
What about “Word Application Scope” and “Replace Text” activity?

It may look like this:
image

Cheers

1 Like

ReplaceDynamicfieldusingdictionary.xaml (11.0 KB)

i am trying to accomplish as in attached code

NewText=
OldText.Replace(Key1,value1).Replace(Key2,value2).Replace(Key3,value3).Replace(Key4,value4).

so how do i call key and values there from dictionary
hope i was able to explain the query

reason why i need to use dictionary because there are more than 15 dynamic fields

1 Like

Hi @Vikram212

Please see this example I made, it uses a for each loop to go through all dictionary elements to replace the values:
ReplaceFromDictionary.zip (2.2 KB)

2 Likes

If dictionary has fixed number of elements and you like to use single line assign you could use this:
NewText= OldText.Replace(Key1,dict1.item(Key1)).Replace(Key2,dict1.item(Key2)).Replace(Key3,dict1.item(Key3))......

Cheers

2 Likes

Thanks @loginerror …i think this should work
Will there be any slowness in execution while using For loop as compared to using replace function in assign statement ?

NewText= OldText.Replace(Key1,dict1.item(Key1)).Replace(Key2,dict1.item(Key2)).Replace(Key3,dict1.item(Key3))

1 Like

I have no idea about performance difference of the two approaches. Likely it would be only detectable in case of hundreds of iterations.

Personally I would rather use the loop as this is more flexible.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.