I have a dynamically formed string like - part1.abc.part2.abc.part3.abc
In this string I want to know position of second to last \".\" so that i can split string as
This would be the solution, with the best possible performance (it probably won't get much faster and memory lightweight than this, unless you want to go the unsafe route):
public static int LastIndexOf(this string str, char charToSearch, int repeatCound)
{
int index = -1;
for(int i = str.Length - 1; i >= 0, numfound < repeatCound)
{
if(str[i] == charToSearch)
{
index = i;
numfound++;
}
}
return index;
}