Separate by space, then for each component of the split, divide it by : Then act accordingly. Roughly speaking:
string s = "from:devcoder hasattachments:true mySearchString on:11-aug"; var components = s.Split(' '); var blocks = components.Select(component => component.Split(':')); foreach(var block in blocks) { if(block.Length == 1) { Console.WriteLine("Found {0}", block[0]); } else { Console.WriteLine( "Found key-value pair key = {0}, value = {1}", block[0], block[1] ); } }
Output:
Found key-value pair key = from, value = devcoder Found key-value pair key = hasattachments, value = true Found mySearchString Found key-value pair key = on, value = 11-aug
The output from the second line:
Found mySearchString Found key-value pair key = from, value = devcoder Found key-value pair key = on, value = 11-aug Found anotherSearchKeyword
jason source share