问题在于如何在脚本中处理NULL
值。 方法Row.Hashtags.ToString().Split(new char[] { ' ' }, StringSplitOptions.None)
无法处理NULL
值。
要解决此问题,我们可以在使用Split
函数之前检查NULL
值。与此更换你的代码:
// Method that will execute for each row passing
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
//Check if the value is null before string split
if (Row.Value_IsNull == true)
{
Output0Buffer.AddRow();
Output0Buffer.SplitID = Row.ID;
Output0Buffer.SplitValue = Row.Value;
}
else
{
string[] SplitArr = Row.Value.ToString().Split(new char[] { ' ' }, StringSplitOptions.None);
// Counter var used the loop through the string array
int i = 0;
// Looping through string array with student names
while (i < SplitArr.Length)
{
// Start a new row in the output
Output0Buffer.AddRow();
Output0Buffer.SplitID = Row.ID;
// This is the splitted column. Take the [n] element from the array
// and put it in the new column.
Output0Buffer.SplitValue = SplitArr[i];
// Increase counter to go the next value
i++;
}
}
}
我使用的投入ID
和Value
,且输出SplitID
和SplitValue
。将它们重命名为您的选择,但请记住将它们添加到脚本组件中。