Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Another way to loop
// Alternative looping.
// I wouldn't do this using a foreach loop, but it is much nicer than
// the original here: http://stackoverflow.com/a/11367974/707111
public int getNthIndex(string str, char c, int n)
{
int index = 0;
int count = 0;
if(n == 0)
return -1;
foreach(char i in str)
{
if (i == c) {
count++;
if (count == n)
return index;
}
index++;
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.