How to find and replace a string in excel

Hi All,

I am facing difficulty in replacing the string in excel.
For eg:
image
This is the sample file, “Repair” needs to be replaced with “Lite Repair”. But in my code where ever it checks for Repair its replacing with “Lite Repair”.
“Not Repair” is replacing as “Not Lite Repair”.
I used
image
row(1).ToString.Replace(“Repair”, “Lite Repair”)
Seq replace.xaml (12.8 KB)

This should not happen.
What changes i need to do.
Please help me.

Thanks & Regards,
Lakshmi

Hello @lakshmi.mp ,
Place the assign activity inside if condition and provide the condition as below,
row(1).tostring.trim.tolower=“repair”

In this way, it will replace only the value which you want to change.

1 Like

You could use System.Text.RegularExpressions.Regex.Replace(row(1).ToString.Trim, “^Repair”, “Lite Repair”)

1 Like

Hi @Dharunya_Devi @TimK ,

image
If row(0) found 32 in col A then row(1) Lite repair needs to be replaced with cur repair


I used if condition is placed inside for each row but not replacing “Lite Repair” with “Cur Repair”
row(1).ToString.Replace(“Lite Repair”, “Cur Repair”)

What changes needs to be done.
Please help.

Thanks ,
Lakshmi

Hi @lakshmi.mp ,

Goto else in row(1).tostring.trim.tolower=“repair” condition and place the assign activity, then replace - row(1).ToString.trim.tolower.Replace(“lite repair”, “Cur Repair”)

Sometime it might be due to case mismatch.

1 Like

@Dharunya_Devi ,
image

i used row(1).ToString.trim.tolower.Replace(“lite repair”, “Cur Repair”) in else part its replacing the highlighted columns also only if row(0) contains 32 it has to replaced with cur repair.
Earlier highlighted columns data was Lite Repair.

Thanks,
Lakshmi

Hi @lakshmi.mp ,

Please place the assign in the second if else found which i have highlighted below,

1 Like

Hi @Dharunya_Devi ,

Thanks a lot for helping. Its working now.

Regards,
Lakshmi

1 Like

Hi @lakshmi.mp , if u need to replace all “Repair” to “Lite Repair”, u can try this one.
Testing Project.zip (1.7 MB)

1 Like

Hi @Felix_Effendi ,

Thanks for providing another solution.
I will go through it.

Thanks & Regards,
Lakshmi

U’re welcome. Please go through it, then see if that is what u want. If it’s correct, please set is as a solution. Thank u.

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