質問

I am currently creating an OpenFileDialog, where I have created some filters for importing some files.

Currently my filters are:

var ofd = new OpenFileDialog();
ofd.Filter = "Supported files|*.dat;*.xlsx;*.csv;*.txt

The user should also be able to import any file with an numeric extension like:

.1337, .42, .007

I am aware it is possible to create a filter like below to match [00000, 99999]

var sb = new StringBuilder("Numeric Files |");
for (int i = 0; i < 99999; i++)
{
  sb.Append("*." + (i + ";").PadLeft(5, '0'));
}
ofd.Filter = sb.ToString();

But this results in an awfully slow pattern matching for each possibility, and I feel there should be some other way.

I have also considered accepting all files in the dialog, and filtering the extensions out afterwards, but I would like to know if there is another way.

The question is now:

Is there a way to use a regular expression or the like to match the above?

Hope you can help :)

役に立ちましたか?

解決

maybe better make your own implementation and derive from FileDialog (OpenFileDialog is sealed), with possibility to add regex as Filters

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top