regex split implementation


  • hi

    I have created a function to implement the regex.split in sql. Here's my 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;
            return ToIndexedValue<string>(Regex.Split(input.Value, pattern.Value, Options));
        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?
    Tuesday, August 03, 2010 3:25 PM


  • Hi Bob

    Yes there's no problem to the code, i found out, i'm supplying the wrong pattern :(

    • Marked as answer by Syslock Thursday, August 05, 2010 9:49 AM
    Thursday, August 05, 2010 9:49 AM

All replies