Search string in datatable using wildcards


#1

Dear all,

I’m struggeling with this topic:

I have a list (using for each to iterate through it), with strings (e.g. “OK_riskprofile_2907_Ledger_20180601_tm_20180630.xlsx”, “production_care_make__2018_05-07-2018.xlsx” ). Now it needs to match a value in a datatable. So within the for each I have a for each row. Now the hard part is, the row(0).tostring gives values such as:

“&outall.\OK_riskprofile&riskprofile.Ledger&Ledgerdate.tm&Ledgerdateend…xlsx”
“&outall.\production_care_make_S&Year._&DateToday…xlsx”

So I am searching for a method to use wildcards such as:

“OK_riskprofileLedgertm*.xlsx”
“&outall.\production_care_make_S_.xlsx”

Does anyone have an idea? Can i use ismatch or regex? Or do I need split and then iterate? How can I make that variable?

Cheers,
Rob


#2

Why don’t you use .Contains method?
it help you check whether a part of string is present in a particular string or not!
I maybe not correct, but this might solve your problem!


#3

Yeah, you can use a Regex pattern.

System.Text.RegularExpressions.Regex.Match(row(0).ToString, "OK_riskprofile(.*)Ledger(.*)\.xlsx”).Success

Or something like that.
.Success will return True or False. You can probably use the IsMatch activity also with a pattern.

Regards.


#4

Thanks for the suggestion, however the strings have comparable number of characters and within this string, the characters differ. So unfortunately contains does not work.


#5

Thanks that worked! I even used the string with wildcards as a variable:

   variable = regex.replace(item, "[0-9]", "(.*)")

    regex.ismatch(row(0).tostring, variable)

Thanks for your suggestion!!