Basically, you want to find the substringCount
th occurrence of '_' in the string, and return all the characters before that.
Basing on the code from http://stackoverflow.com/a/11363213/1108056 https://stackoverflow.com/a/11363213/1108056
private int IndexOfNth(string str, char c, int n)
{
int index = -1;
while (n-- > 0)
{
index = str.IndexOf(c, index + 1);
if (index == -1) break;
}
return index;
}
public string GetSubstring(string input, int count, char delimiter)
{
return input.Substring(0,IndexOfNth(input, delimiter, count));
}
Basically, you want to find the substringCount
th occurrence of '_' in the string, and return all the characters before that.
Basing on the code from http://stackoverflow.com/a/11363213/1108056
private int IndexOfNth(string str, char c, int n)
{
int index = -1;
while (n-- > 0)
{
index = str.IndexOf(c, index + 1);
if (index == -1) break;
}
return index;
}
public string GetSubstring(string input, int count, char delimiter)
{
return input.Substring(0,IndexOfNth(input, delimiter, count));
}
Basically, you want to find the substringCount
th occurrence of '_' in the string, and return all the characters before that.
Basing on the code from https://stackoverflow.com/a/11363213/1108056
private int IndexOfNth(string str, char c, int n)
{
int index = -1;
while (n-- > 0)
{
index = str.IndexOf(c, index + 1);
if (index == -1) break;
}
return index;
}
public string GetSubstring(string input, int count, char delimiter)
{
return input.Substring(0,IndexOfNth(input, delimiter, count));
}
Basically, you want to find the substringCount
th occurrence of '_' in the string, and return all the characters before that.
Basing on the code from http://stackoverflow.com/a/11363213/1108056
private int IndexOfNth(string str, char c, int n)
{
int index = -1;
while (n-- > 0)
{
index = str.IndexOf(c, index + 1);
if (index == -1) break;
}
return index;
}
public string GetSubstring(string input, int count, char delimiter)
{
return input.Substring(0,IndexOfNth(input, delimiter, count));
}