If you use the GetNthIndex method from this question , you can use String.Substring :
public int GetNthIndex(string s, char t, int n) { int count = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == t) { count++; if (count == n) { return i; } } } return -1; }
So you can do the following:
string sample = "A, ABC, 1, ACS,,"; int index = GetNthIndex(sample, ',', 4); string result = sample.Substring(0, index);
Donut source share