hi
I have created a function to implement the regex.split in sql. Here's the code:
private static IEnumerable<IndexedValue<T>> ToIndexedValue<T>(IEnumerable<T> list)
{
int idx = 1;
foreach (T value in list)
yield return new IndexedValue<T>(++idx, value);
}
private struct IndexedValue<T>
{
public int Index;
public T Value;
public IndexedValue(int index, T value)
{
Index = index;
Value = value;
}
}
[SqlFunction(FillRowMethodName = "FillSplit",
TableDefinition = "[ID] int, [Value] nvarchar(max)")]
public static IEnumerable RegexSplit(SqlString input, SqlString pattern)
{
if (input.IsNull)
input = String.Empty;
if (pattern.IsNull)
pattern = String.Empty;
try
{
return ToIndexedValue<string>(Regex.Split(input.Value, pattern.Value, Options));
}
catch
{
throw;
}
}
public static void FillSplit(object obj, out int id, out SqlString value)
{
IndexedValue<string> iv = (IndexedValue<string>)obj;
id = iv.Index;
value = iv.Value;
}
However when i try it, i get id values but empty text values. Can someone help?