I want filter one “yyy” column if found 7 digit number start with "002"or "003 or “004” and if 5 digit start with “2” or “3” or “4” we should add in valid sheet else invalid sheet.
Please help me anyone for this.
I have attachment sample for your reference digit.xlsx (10.7 KB)
(From d In dtData.AsEnumerable
Let v = d(1).toString.trim
Let chk = Regex.IsMatch(v,"(^00[234]\d{4}$)|(^[234]\d{4}$)")
Where chk
Select r = d).CopyToDataTable
feel free to use the columnname d(“YourColName”) instead of the index d(1)
dt_Invalid=dt_Input.AsEnumerable().Where(Function(row) Not System.Text.RegularExpressions.Regex.IsMatch(row(“yyy”).ToString(),
“(00[234]\d{4}$)|([234]\d{4}$)”)).CopyToDataTable()
hi yes as @Sudeen_Raj_Shetty meantion you can used linqs .If LINQ is unfamiliar Main.xaml (22.5 KB)
to you,you can use traditional Loop Approach.i have upload a sample workflow .
Best and easiest solution would be to use Linq queries only as mentioned by @ppr and @Sudeen_Raj_Shetty
If you are new to this concept - I am giving you the step-by-step details and few minor points to be considered while using the regular expressions
Only 6 steps are involved for this
Open the excel file where you need to apply the filter
Read the data table and store to a variable (dtTable)
Assign new data table variable (example dtvalid) with below regular expression as mentioned above. Make sure you have imported System.Text.RegularExpression in your project imports
dtvalid =
(From d In dtTable.AsEnumerable
Let v=d(1).ToString.Trim
Let chk =System.Text.RegularExpressions.Regex.IsMatch(v, “(^00[234]\d{4}$) | ([1]\d{4}$)”)
Where chk
Select r=d).CopyToDataTable
Assign new data table variable (example dtinvalid) with below regular expression as mentioned above. Only difference to make is in where condition. Where chk=false
dtinvalid =
(From d In dtTable.AsEnumerable
Let v=d(1).ToString.Trim
Let chk =System.Text.RegularExpressions.Regex.IsMatch(v, “(^00[234]\d{4}$) | ([2]\d{4}$)”)
Where chk=false
Select r=d).CopyToDataTable