Replace string in excel

Hi team,

I want to replace “-46546” this string in excel with “P0” string.
This string will be present in row(0) in excel on multiple times.

Regards,
sushant

1 Like

Hi @sshitol
If you can install package “BalaReva.Excel.Sheets.FindReplace”, then it will be easy for you to find/replace

1 Like

Hi @sshitol

Use the below steps…

  • use read range to read the excel into a datatable.
  • use For Each Row to loop through each row of the data table
  • within the loop use an IF activity to check for the specific value

If row(0).ToString.Equals("-46546")

  • now in the Then segment of the if condition, use assign activity to replace it
    Row(0) = “P0”
1 Like

@Lahiru.Fernando

This condition will check if complete row(0) is equal to “-46546” and not part of the string per the requirement.
Moreover,

this assignment will replace all of the string in row(0) with P0, instead of part of it, incase it finds a matching string “-46546”.
Please correct me if Iam wrong.

2 Likes

@sawaseem

Oh yeah… thanks for pointing it out :slight_smile:

Yep… it will check the whole string for the value. So if we want to see if the string contains the value somewhere… we can use below

Row(0).ToString.Contains("-46546")

Yep… correct… so for that we can use string replace
Row(0) = Row(0).ToString.Replace("-46546",“P0”)

Thanks again bro for correcting :slight_smile:

2 Likes

@Lahiru.Fernando Thanks man.:+1:

1 Like