Mufasa said:
Does anybody have any code that will take a search string and parse it in to
the appropriate parts?
For instance: +google -news -bush
For inspiration see below.
Arne
==========================================================
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);
}
}