kit2815
February 15, 2022, 6:39am
1
Hi Everyone!
I am checking a Row Item called “Name In Bank” under for each activity.
I would like to check whether the names in each row contains alphabets, numbers or signs as below:
0-9
A-Z
a-z
{Space}
?
:
'
(
)
+
,
-
.
/
I have tried using Row.Item(“Name In Bank”).ToString.All(function (c) Char.IsLetterOrDigit(c)) and adding OR with Contains, but it does not work.
Are there anyways to set the IF condition at once, please? Or is it better for me to work it in Filter Datatable?
Yoichi
(Yoichi)
February 15, 2022, 6:55am
2
Hi,
Can you try the following?
Check if it includes any character of them (at least 1 character)
System.Text.RegularExpressions.Regex.IsMatch(yourString,"[0-9A-Za-z ?'{}+,\-./]")
Check if it consists only the above characters
System.Text.RegularExpressions.Regex.IsMatch(yourString,"^[0-9A-Za-z ?'{}+,\-./]+$")
Regards,
You want to remove this rows from your DT or you want DT containing only theese rows?
kit2815
February 15, 2022, 7:20am
5
Hi @gabrielribas4
Maybe I can explain a little bit more.
I need to check whether the row items include the mentioned alphabets, numbers and signs first.
After that, I need to check whether the row items are started with the signs, space or blank characters.
I want to keep the rows that do not fulfil either one of the 2 requirement.
Do you have any idea? Thanks a lot.
Yeah! Lets do this! I just need some sleep, I’m already past the hour lol.
If no one comes up with the solution, I’ll bring it to you in the morning!
kit2815
February 15, 2022, 7:40am
7
Sure, no hurry. Thanks Gabriel again!
kit2815
February 15, 2022, 8:04am
8
Hi @Yoichi
Could I use it in Filter Datatable?
As I am now using: “Name In Bank” != System.Text.RegularExpressions.Regex.IsMatch(yourString,“+$”) to keep the row item with any characters not in the range.
But when I add ^ in a row item, other names without the sign ^ still show in the result Datatable.
Yoichi
(Yoichi)
February 15, 2022, 8:16am
9
Hi,
Unfortnately, FilterDataTable activity doesn’t support regex.
I think rows which you want to remove is “first character is 0-9A-Za-z and remains are consist only [0-9A-Za-z ?'{}+,-./]”, right? If It’s correct, the following might work.
dt = dt.AsEnumerable.Where(Function(r) (Not System.Text.RegularExpressions.Regex.IsMatch(r("yourColumn").ToString,"^[0-9A-Za-z][0-9A-Za-z ?'{}+,\-./]*$"))).CopyToDataTable
Regards,
kit2815
February 15, 2022, 9:53am
11
Hi @Yoichi
I think your formula works. Many thanks for your help.
But here comes to another question as I have three conditions now:
Condition 1: Row.Item("Bank Acct No").ToString.IsNumeric (But Following an assign function of Decimal. Parse before Condition 2 if it is true)
Condition 2: Row.Item("Bank Acct No").ToString.Length >6 And Row.Item("Bank Acct No").ToString.Length <16
Condition 3: Not System.Text.RegularExpressions.Regex.IsMatch(r("Name In Bank").ToString,"^[0-9A-Za-z'()][0-9A-Za-z ?'()+,\-./]*$"))
I want to keep the row items that cannot fulfil either one of the conditions. Could I write the range at once without merging datatables?
Yoichi
(Yoichi)
February 15, 2022, 10:33am
12
Hi,
We can combine them with logical operator. The following probably works.
dt = dt.AsEnumerable.Where(Function(r) (Not Decimal.TryParse(r("Bank Acct No").ToString,New Decimal)) OrElse (r("Bank Acct No").ToString.Length <=6 OrElse r("Bank Acct No").ToString.Length >=16 ) OrElse (Not System.Text.RegularExpressions.Regex.IsMatch(r("Name In Bank").ToString,"^[0-9A-Za-z][0-9A-Za-z ?'{}+,\-./]*$"))).CopyToDataTable
Regards,
1 Like
system
(system)
Closed
February 18, 2022, 10:33am
13
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.