Linq query to check if the column value has quotes and if present replace it with blank

Hi all,

Question- Linq query to check if the column value has quotes and if present replace it with blank.

Ex-
Input

column1
ABC
Def
“Xyz”

Output
ABC
Def
Xyz

Any idea?

Thank in advance.

Hi @Ray_Sha1 ,

Are we Checking for Specific Columns or all Columns ? Also Do you want to Replace Quotes only at the Start/End or if it is present anywhere in the String ?

@Ray_Sha1

Check below for your reference

Use Invoke code and write as below
dttt.AsEnumerable().ToList.foreach(Sub(row) row("Column1")= row("Column1").tostring.replace(""""," ").Trim)

Hope this will help you

Thanks

1 Like

Hi @supermanPunch,
Specific column called column 1.
Quotes are present in the start and end.

Thanks!

@Ray_Sha1

In Invoke code you need to use create an argument and pass the datatable, Direction should be In/Out

Thanks

2 Likes

hey

try the following

Main.xaml (11.4 KB)

Regards!

1 Like

@Ray_Sha1

Here is the sample workflow

LinqReplace.xaml (10.9 KB)

Mark as solution if this helps

Thanks

3 Likes

@Ray_Sha1 ,
Though we would suggest to use For Each Row Activity and Update values accordingly, since it is a Simple Update, the below Steps maybe an alternate method to get the Required Result :

  1. Firstly, Get all the Column Names in a String Array variable using the Expression below in Assign Activity.
columnNames = DT.Columns.Cast(Of DataColumn).Select(Function(x)x.ColumnName.ToString).ToArray

Here, columnNames is the variable of type Array of String, DT is the Input Datatable.

  1. Next, we use the Below Assign to Create a Clone of the Input Datatable.
OutputDT = DT.Clone
  1. Next, we can use the Below Linq in an Assign Activity to remove the Quotes at the Start/End.
OutputDT = (From x In DT
Let ra = columnNames.Select(Function(c)If(c.Equals("YourSpecificColumnName"),x(c).ToString.Trim("""".ToCharArray),x(c).ToString)).ToArray
Select OutputDT.Rows.Add(ra)).CopyToDatatable

Let us know if this doesn’t work.

Hi,
The first query has an issue with it.
Thanks

Hi @Srini84, @fernando_zuluaga,

Thanks for the reply.
It working solution.

Great day

lets append asEnumerable: From x In DT.AsEnumerable()

2 Likes

@Ray_Sha1 ,

Could you Let us know what was the issue faced ?

Ppr helped you with it. The query is faulted and we’ll have to use asenum

1 Like

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