J'ai créé une fonction pour implémenter le regex.split en sql. Voici le code:implémentation fractionnée regex pour le serveur SQL
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;
}
Cependant quand je l'essaie, j'obtiens des valeurs d'id mais des valeurs de texte vides. Quelqu'un peut-il aider?
C'est dupe, à la recherche d'origine. Edit: Pas vraiment dupe, mais j'ai dupe ma réponse :) – leppie