using System.Collections.Generic;
public static void Main()
var requestedPrivileges = "ClientId = 123456 And ClientId = 56789 AND (EmpUid = 12345978)";
var sp = requestedPrivileges.Split(new string[] { "ClientId" }, StringSplitOptions.None);;
var split = SplitString("ClientId", requestedPrivileges);
Console.WriteLine(sp.Count());
Console.WriteLine("ClientId" + s);
private static List<string> SplitString(string key, string stringToSplit)
List<string> splitString = new List<string>();
var fromIndex = GetFirstIndex(key, stringToSplit);
var toIndex = GetFirstIndex(key, stringToSplit.Substring(key.Length));
splitString.Add(stringToSplit);
splitString.Add(stringToSplit.Substring(0, fromIndex));
splitString.AddRange(SplitString(key, stringToSplit.Substring(fromIndex)));
splitString.Add(stringToSplit.Substring(fromIndex, key.Length + toIndex));
splitString.AddRange(SplitString(key, stringToSplit.Substring(fromIndex + key.Length + toIndex)));
private static int GetFirstIndex(string key, string stringToSplit)
var index = stringToSplit.IndexOf(key);
if ((index != -1 && minIndex == null) || (index != -1 && index < minIndex))
if (minIndex == null) minIndex = 0;