Hitesh1
(Hitesh)
November 23, 2021, 11:06am
1
Hi Team ,
Can anyone tell me what is wrong with the below syntax, I am trying to filter data table
dtMainReport.AsEnumerable.Where(Function(x) (convert.ToInt64(System.Text.RegularExpressions.Regex.Matches(x(“column”).ToString,“[0-9]\d*(.[0-9]\d+)?”)(0))>50 )).CopyToDataTable
ppr
(Peter Preuss)
November 23, 2021, 11:21am
2
please share some sample values representing the input for the regex. Currently we do see some possible issues with the Linq and regex. Thanks
Hitesh1
(Hitesh)
November 23, 2021, 11:23am
3
In one column there are values like
200 persons
100 persons
50 persons
10 persons
I have to filter this data table where persons are < 50
ppr
(Peter Preuss)
November 23, 2021, 11:31am
4
we can anchor
So a LINQ could look like this:
(From d in dtMainReport.AsEnumerable
Let cnt = System.Text.RegularExpressions.Regex.Match(d("column").ToString,"\d+(?= persons)").Value.Trim
Where CInt(cnt) < 50
Select r=d).CopyToDataTable
Depending on the expected data quality the statement can be adoptet on some more checks and handling defensive an empty filter result
1 Like
Hitesh1
(Hitesh)
November 23, 2021, 11:47am
5
Thankyou for the response , I just want to correct one thing that in place of “Person” there can be any string like
200 as Ram
30 as shyam
150 gopal
ppr
(Peter Preuss)
November 23, 2021, 11:49am
6
give a try with folloing pattern taking the first found number:
\b\d+\b
Hitesh1
(Hitesh)
November 23, 2021, 12:34pm
7
I have kept it in assign and it is showing “type integer is not valid”
I am storing it in DT variable
ppr
(Peter Preuss)
November 23, 2021, 12:38pm
8
check for any values e.g. blank , no valid string parseable to int
This was mentioned by:
1 Like
lakshman
(Ganta lakshman)
November 23, 2021, 2:28pm
9
@Hitesh1
Try below expression.
dtMainReport.AsEnumerable.Where(Function(x) Cint(System.Text.RegularExpressions.Regex.Match(x(“ColumnName”).ToString,"\b\d+\b").Value)>50).CopyToDataTable
1 Like
system
(system)
Closed
November 26, 2021, 2:29pm
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.