Remove data from column

Hi all,

I have an excel in ColumnB I have some data like 001-1 or 002-2 I need to remove -1,-2,-3 from all the rows of columnB.Tge number before - must be there but -and number after - must be removed from all the rows in that column

How to do this. Can you please help me

1 Like

Dear friends plz help me

Hi,

How about the following?

Please set Text format at the cell using FormatCells activity to prevent to omit 0.

Regards,

Sorry i cannot use foreach row as I have huge data

Hi @0bb4628e217fd43ac86ac9294

Try this

(From row In DT.AsEnumerable()
                  Let newValue = System.Text.RegularExpressions.Regex.Replace(row.Field(Of String)("ColumnB"), "-[0-9]+$", "")
                  Select DT.Clone.Rows.Add({row.Field(Of String)("ColumnA"), newValue})).CopyToDataTable()

Cheers!!

Hi,

Use below linq:-

Assign activity:
dataTable = (From row In dataTable.AsEnumerable()
Let newValue = row.Field(Of String)(“ColumnB”).Split("-"c)(0)
Let newRow = row
Select newRow.SetField(“ColumnB”, newValue)).CopyToDataTable()

Thanks

Hi,

Another approach:
How about the following?

image

dt.AsEnumerable.ToList.ForEach(Sub(r)
    r(1)=r(1).ToString.Split("-"c).First()
End Sub
)

Sample
Sample20240316-2a.zip (6.9 KB)

Regards,

1 Like

Thank you all for your help on time

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