Remove specific char's from datatable column without for each

Hi All ,

   i have a datatable where one particular column is having value as "INR 129.00", here i want to remove the INR without using For Each command...pls help me on this any possibilities using LINQ

Hi @fayaz
do one use for each row in datatable

Assign strvar=row(“Value”).ToString

StrArray=strvar.ToString.Split(“INR”.ToCharArray).

Thanks
Ashwin S

Thanks @AshwinS2 , Yes it should work in for each…i was thinking any possibilities without using it and can achieve it with LINQ…

@fayaz

Try below Linq query.

                 newDT = datatable.AsEnumerable().Where(Function(row) row("ColumnName").ToString.Replace("INR", "")) .CopyToDataTable
2 Likes

Hi @fayaz

I was about to say the same

Thanks
Ashwin S

3 Likes

@lakshman Thanks bro, i am facing compilation error as follow " [Getting the error as - option strict on disallows implicit conversions from ‘string’ to ‘boolean’] "…any idea bro?

2 Likes

@fayaz

Sorry… Its my bad. Try below one:

                   DataRow []  newValues = datatable.AsEnumerable().Select(Function(row) row("ColumnName").ToString.Replace("INR ", "")).ToArray
5 Likes

Hi,

How to remove multiple columns in datatable using linq?

@SARITHA_Masani
Can you Open for your question a new topic as IT differs from Origin older Threads topic. Thanks

Hi @lakshman, I am getting the same error, I don’t understand the new code.

can you help? Thanks

@Dev2

Can you please share screenshot of your Input data and expression you are using here. So that I can check and help you better.

image

This is my data, I need to remove the $.

I use this code

dt1.AsEnumerable().Select(Function(row) row(“Name”).ToString.Replace(“$”, “”)).ToArray

but I got the error as - 'option strict on disallows implicit conversions from ‘string’ to ‘boolean’

image

image

@lakshman Hi, it is clear?

@Dev2

Try below expression.

newDT = dt1.Clone

newDT = (From r In dt1.AsEnumerable let ra = r.ItemArray.Select(Function (x) x.ToString.Trim.Replace("$",“”)).toArray() Select newDT.Rows.Add(ra)).CopyToDataTable()

Write above two lines into two different Assign activities and create one new variable named newDT of type DataTable.

1 Like

Thank you @lakshman

1 Like