Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Basically, you want to find the substringCountth 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 substringCountth 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 substringCountth 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));
}
Source Link
Snowbody
  • 8.7k
  • 25
  • 50

Basically, you want to find the substringCountth 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));
}
lang-cs

AltStyle によって変換されたページ (->オリジナル) /