我有一個在C#中實現的代碼,當我嘗試在SSIS組件中實現相同的代碼時,它給了我錯誤如果任何人可以幫助我進行此轉換,這將非常有幫助。SSIS實現中的腳本組件
代碼是
using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
public class Test
{
public static void Main()
{
List<string> thenames = new List<string>(new string[]
{
"XY YZ ZX Jr",
"XY, Jr TR YZ",
"XY Sr YZ.",
"XY YZ Sr",
"XY I YZ",
"XY I YZ",
"XY II, YZ",
"XY YZ II",
"XY YZ III.",
"XY III. Yz."
});
var reg = new Regex(@"\w+", RegexOptions.IgnoreCase);
var titles = new Regex(@"[JS]r|II?I?");
foreach (String str in thenames)
{
var names = reg.Matches(str)
.OfType<Match>()
.Select(m => m.Value)
.ToList();
names.Reverse();
List<string> output = new List<string>();
foreach (String name in names)
{
Match title = titles.Match(name);
if (title.Success)
{
output.Insert(0, name);
}
else
{
output.Add(name);
}
}
output.Reverse();
Console.WriteLine(string.Join(", ", output.ToArray()));
}
}
}
此代碼提供了以下結果
XY, YZ, ZX, Jr
XY, TR, YZ, Jr
XY, YZ, Sr
XY, YZ, Sr
XY, YZ, I
XY, YZ, I
XY, YZ, II
XY, YZ, II
XY, YZ, III
XY, Yz, III
我需要從表發送輸入,並獲得所需的結果。但是,並非從輸入,所以我在SSIS的腳本組件嘗試寫,下面是代碼和錯誤,我面對
using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Text.RegularExpressions;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
var reg = new Regex(@"\w+", RegexOptions.IgnoreCase);
var titles = new Regex(@"[JS]r|II?I?");
foreach (String str in Row.XYZ)
{
var names = reg.Matches(str)
.OfType<Match>()
.Select(m => m.Value)
.ToList();
names.Reverse();
List<string> output = new List<string>();
foreach (String name in names)
{
Match title = titles.Match(name);
if (title.Success)
{
output.Insert(0, name);
}
else
{
output.Add(name);
}
}
output.Reverse();
Console.WriteLine(string.Join(", ", output.ToArray()) + ".");
}
}
}
錯誤:
Cannot convert type 'char' to 'string'
什麼數據類型是XYZ列? –
@KyleHale nvarchar(50) –