// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace E { public class Program { public static void ParseSplit(string s) { string[] parts = s.Split(" ".ToCharArray()); foreach(string part in parts) { if(part[0] == '+') { Console.WriteLine("Include : " + part.Substring(1)); } else if(part[0] == '-') { Console.WriteLine("Exclude : " + part.Substring(1)); } } } private static readonly Regex incl = new Regex(@"(?:\+)(\w+)(?: |$)", RegexOptions.Compiled); private static readonly Regex excl = new Regex(@"(?:\-)(\w+)(?: |$)", RegexOptions.Compiled); public static void ParseRegex(string s) { foreach(Match m in incl.Matches(s)) { Console.WriteLine("Include : " + m.Groups[1].Value); } foreach(Match m in excl.Matches(s)) { Console.WriteLine("Exclude : " + m.Groups[1].Value); } } public static void Main(string[] args) { string s = "+google -news -bush"; ParseSplit(s); ParseRegex(s); } } }