I have a string that has the following format:
string sample = \"A, ABC, 1, ACS,,\"
As you can see, there are 5 occurences of the ,>
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 could do the following:
string sample = "A, ABC, 1, ACS,,";
int index = GetNthIndex(sample, ',', 4);
string result = sample.Substring(0, index);