Replace specific values(Nà) of all columns of datatable - Reopen

Hi All,

I want to replace value with blank one. I am able to replace other text values, since seems to be special symbol it is not getting replaced in data table.

Also if possible want to add multiple replace condition in same linq query.

Please refer below Linq which need to be modified.

(From r In dt_Final.AsEnumerable
Let ra = r.ItemArray.Select(Function (x) x.ToString.Trim.ToLower.Replace(“nà”,“”)).toArray()
Select dt_CSSorted.Rows.Add(ra)).CopyToDataTable()

@Palaniyappan @ppr @Yoichi

Thanks,
Rishi

@rishiathawale

Is it possible to provide a sample file?

Cheers

Hi @rishiathawale
How many row in your data?
If LinQ can not update, you can use activity for each row
assign value
regards,

Hi @Anil_G

This is how data table looks like. Where “Nà”, “NA” to be replaced by blank and “res” by “yes”

image

@Nguyen_Van_Luong1 datatable has dynamic and 1500+ rows hence trying to do it by linq.

Thanks

@rishiathawale

do you mind sending a file…want to see how thye look in UiPath when read

cheers

@Anil_G Here it is.

New folder.zip (13.6 KB)

Maybe Asc Code analysis can help:
grafik

@ppr Can you pls elaborate how can we achieve that?

Hi @rishiathawale ,

Could you let us know if you were receiving an Error when used the Above Code or was it not giving the Expected results ?

@supermanPunch

I am able to replace Nà now. but can you help using multiple replace condition in same linq. I am trying using OR condition, its throwing error.

@rishiathawale ,

We would require to know the conditions or Samples for deriving the logic.

This is how I am trying, error - does not allow to convert string to double.

If I remove OR condition it works well

@rishiathawale ,

I believe the Expression should be changed to the below :

(from r in dt.AsEnumerable
let ra = r.ItemArray.Select(Function(x) if(x.ToString.Trim.ToLower.Equals("nà"),"",If(x.ToString.Trim.ToLower.Equals("res"),"yes",x.ToString))).ToArray()
select dt_CSSorted.Rows.Add(ra)).CopyToDataTable

Also Interesting to know that the workflow shared was built in C# but a Vb.net syntax is accepted.

@supermanPunch

What if I want to add more than 2 conditions? I see you have used nested IF.

Edited: Able to build the query for more that 2 conditions. Thanks

there will be a certain threshold where a resulting LINQ risks to get over-LINQed

One technique could be to work with a LookupDict

Assign Activity:
dictLK = new Dictionary(Of String, Object) From {{"res","yes"}, {"nà", ""}}

dtResult =

(From d In dtData.AsEnumerable
Let ra = d.ItemArray.Select(Function (x) If(dictLK.ContainsKey(x.ToString.Trim().toLower()),dictLK(x.ToString.Trim().toLower), x)).ToArray()
Select r= dtResult.Rows.Add(ra)).CopyToDataTable

@ppr
Okay, I didnt face such issue yet, but yes due to over conditioned that might happen.

I will try LookupDict method. Thanks for pointing out.

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