public static FilterItem[] ParseFilterString(string filterString, string existing, out int existingIndex)
{
var result = new List<FilterItem>();
existingIndex = -1;
string[] items = filterString != string.Empty ? filterString.Split('|') : new string[0];
if ((items.Length % 2) != 0)
{
throw new ArgumentException(
@"Filter string you provided is not valid. The filter string must contain a description of the filter,
followed by the vertical bar (|) and the filter pattern. The strings for different filtering options must also be
separated by the vertical bar. Example: " + "\"Text files|*.txt|All files|*.*\""
);
}
for (int n = 0; n < items.Length; n += 2)
{
var item = new FilterItem(items[n], items[n + 1]);
result.Add(item);
if (item.Filter == existing) existingIndex = result.Count - 1;
}
return result.ToArray();
}
}