【问题标题】:Passing data between Collections and Regex.Match method在 Collections 和 Regex.Match 方法之间传递数据
【发布时间】:2019-12-14 07:43:21
【问题描述】:

我正在构建一个执行以下操作的 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.  

我做错了什么?对此我将不胜感激,谢谢。

【问题讨论】:

  • 您忘记将列添加到您的localOutputlocalOutput.Add("ColumnName", typeof(string))

标签: c# .net regex blueprism


【解决方案1】:

首先,您必须定义列:

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

然后您可以添加新行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多