There are two ways to do this.
The first is to split the string twice:
string value = "P 2016-10-17,P 2016-10-18,P 2016-10-19,P 2016-10-20,P 2016-10-21";
string[] parts = value.Split(',');
foreach (string part in parts)
{
string[] subParts = part.Split(' ');
if (subParts.Length > 0) Console.WriteLine(subParts[0]);
}
The second is to use a regex:
string value = "P 2016-10-17,P 2016-10-18,P 2016-10-19,P 2016-10-20,P 2016-10-21";
MatchCollection matches = Regex.Matches(value, @"(?<=^|,)(?<Prefix>.+?)(?=\s)");
foreach (Match m in matches)
{
Console.WriteLine(m.Value);
}
The regex is a little more complex, but a lot more flexible!