Hi ,I need to check if input string is present in datatable.
I m using output datable activity to convert it into string and using strngDt.contains(input_str)
Assume my datatable has values like Hip ,Hippo, Shift ,History and input string is Hi .Flag should be ideally false as there is no “Hi” in Dt .But I m getting flag as true as the words in dt contains letter H and i together .How to solve this
Yoichi
(Yoichi)
November 11, 2022, 9:56am
2
HI,
Can you try the following?
strTarget ="Hi"
Then
System.Text.RegularExpressions.Regex.IsMatch(strDt,"\b"+System.Text.RegularExpressions.Regex.Escape(strTarget)+"\b")
Please note that it’s better to evaluate each item in datatable because the above can’t evaluate some characters such as comma.
Regards,
Yoichi
(Yoichi)
November 11, 2022, 10:00am
3
Hi,
The following is better, i think. This will check each item if contains target string as word.
dt.AsEnumerable.Any(Function(r) r.ItemArray.Any(Function(o) System.Text.RegularExpressions.Regex.IsMatch(o.ToString,"\b"+System.Text.RegularExpressions.Regex.Escape(strTarget)+"\b")))
Regards,
Thanks.It is partially working .my input string will also be “Hi ,I am Hippo” in this case flag should be true as dt contains the word hippo .
Yoichi
(Yoichi)
November 11, 2022, 10:27am
5
HI,
You mean your target string is “Hi”, “I” , “am” and “Hippo”, right? If so, the following will work.
strTarget ="Hi ,I am Hippo"
arrTarget = System.Text.RegularExpressions.Regex.Matches(strTarget,"\w+").Cast(Of System.text.RegularExpressions.Match).Select(Function(m) m.Value).ToArray()
Then
dt.AsEnumerable.Any(Function(r) r.ItemArray.Any(Function(o) arrTarget.Any(Function(s) System.Text.RegularExpressions.Regex.IsMatch(o.ToString,"\b"+System.Text.RegularExpressions.Regex.Escape(s)+"\b",System.Text.RegularExpressions.RegexOptions.IgnoreCase))))
Sequence.xaml (8.4 KB)
Regards,
1 Like
system
(system)
Closed
November 14, 2022, 11:22am
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.