fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var s = "&RPork && Beans&CDocument Title";
  11. var result = Regex.Split(s, "(&[LRC])")
  12. .Where(x => !string.IsNullOrWhiteSpace(x))
  13. .ToList();
  14. var data = result.Where((c,i) => i % 2 == 0).Zip(result.Where((c,i) => i % 2 != 0),
  15. (delimiter, value) => new KeyValuePair<string, string>(delimiter, value));
  16. foreach (var kvp in data)
  17. Console.WriteLine("Delimiter: {0}\nValue: {1}", kvp.Key, kvp.Value);
  18. }
  19. }
Success #stdin #stdout 0.04s 134592KB
stdin
Standard input is empty
stdout
Delimiter: &R
Value: Pork && Beans
Delimiter: &C
Value: Document Title