Replace Multiple Values in Notepad

Dear Forum Members,

I have created a workflow in which BOT will read the Text file and in the text file, BOT needs to perform multiple replacements. And the values for replacements, BOT will pick from the excel file.

Now, multiple replacements I can perform like: NotepadText.Replace(oldvalue,Newvalue).Replace(oldvalue,Newvalue) and so on.

Like this, I can perform multiple replacements but my requirement is: I need to perform multiple replacements where excel can have “n” number of columns and also “n” number of replacements could be performed. I want to make the solution dynamic.

Any help will be appreciated, Thanks in advance.

1 Like

Hey @dimple.khurana,

Assuming you have an excel with two columns.

Column1 - Old string to replace

Column2 - New string

These steps may help you

  1. Read excel into a data table - DT_ReplaceData

  2. Use a for-each row for DT_ReplaceData

  3. Inside for-each row, Add a replace activity or assign with below code.

NotepadText = NotepadText.Replace(row("Column1").ToString, row("Column2").ToString)

Hope this helps.

Thanks :slight_smile:

1 Like

Thanks for your response.

I have an excel file with say 100 records and 10 columns. Now I would need to perform 10 replacements for these 100 records. The text from which I need to replace the text is in the text file and the text to which I need to replace text is in excel file. How this method will be used in that case.

For this, I would need to write 1000 rows, 10 for each record. And also the number of columns is not fixed. It can be 1 , 10 or even 100.

Correct me, if I am wrong. Thanks

1 Like

Hi @dimple.khurana

I could not understand ur Requirement like what u mean by no of column do it means it is the number of string to be replaced in notepad text ?

@dimple.khurana,

How you will identify the text to be replaced which is there in the text file alone.

Hey @dimple.khurana,

Please find the updated step 3.

  1. Inside for-each row, Use another for-each for row.ItemArray and pass item in replace

Then continue with other steps as above.

Hope this helps.

Thanks :slight_smile:

When we are using the for each row for excel, it will iterate through each row. Then second for each is for what purpose. I am not getting it properly.

Because when we use a loop for this, it will take value one by one and save in a variable then when it goes second time, the first value which is replaced, it would be lost.

If possible, Could you please provide a sample workflow. It will be a great help.

Thanks

1 Like

Sure, If you can provide with the test files please…

I will try in making a sample.

Thanks :slight_smile:

I have attached the sample files. Please refer to it. Sample Files.zip (7.9 KB)

The text file is not fixed, it can change anytime and excel file can have more or less columns. I am looking for a dynamic solution.

Thanks for your time and help.

1 Like

Hey @dimple.khurana,

Please check this sample output.

PFA - CertificateGenerator.zip (10.9 KB)

This works irrespective of number of columns in excel, Only thing is to make sure column names in excel are same as replace text in notepad text.

Thanks :slight_smile:

Awesome. That’s the expected output which I was looking for. Thanks a lot for your help and time. :slightly_smiling_face:

1 Like

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