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 ?



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

It may look like this:



ReplaceDynamicfieldusingdictionary.xaml (11.0 KB)

i am trying to accomplish as in attached code


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


Hi @Vikram212

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


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))......



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))


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.

closed #8

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