在集合和 Regex.Match 方法之间传递数据

Passing data between Collections and Regex.Match method

我正在构建一个执行以下操作的 BP 对象:

  1. 使用标准 Excel VBO 将 Excel 文件中某些行的文本捕获到 Blueprism 集合中。
  2. 将该集合的内容放入 Regex.Match 代码阶段,以便从集合中的每一行中提取特定值。
  3. 然后代码阶段应该用提取的值填充另一个(输出)集合。

Blueprism 似乎使用 c# DataTable 对象进行集合?我尝试使用 List<> 对象,但 BP 不会隐式转换这些对象(或其他任何与此相关的对象),所以我想我必须使用 DataTable。
下面代码中的输入和输出变量(第一行和最后一行)是 BP 对象中实际 BP 集合的包装器。

        DataTable localList = input;
        DataTable localOutput = new DataTable();
        DataRow[] rows = localList.Select();


        while (localList != null)
        {
            for (int i = 0; i < rows.Length; i++)
            {
                string indexValue = Convert.ToString(localList.Rows[i]);

                //example Regex
                string sPattern1 = "[0-9]{5,8}[A-Z][A-Z]";
                Match match1 = Regex.Match(indexValue, sPattern1);

                ///same thing with sPattern2, 3, 4, 5 & 6... with corresponding match2, 3, etc...


                if (match1.Success || match2.Success || match3.Success || match4.Success ||
                match5.Success || match6.Success)
                {
                    localOutput.NewRow();
                    localOutput.Rows.Add(indexValue);
                }
                else
                {
                    localOutput.NewRow();
                    localOutput.Rows.Add("Not Found");
                }
            }
        }
              output = localOutput.Select();

所以,这段代码编译正常,即不会抛出任何类型转换错误或任何类似我尝试使用 List<> 的错误,但是当我 运行 对象 BP 抛出以下 运行时间异常:

Internal : Could not execute code stage because exception thrown by code stage: Input array is longer than the number of columns in this table.  

我做错了什么?如果有任何帮助,我将不胜感激。谢谢。

首先,您必须定义列:

DataTable localOutput = new DataTable();
localOutput.Columns.Add("Column1", typeof (string));

然后您可以添加新行。