Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // from http://stackoverflow.com/a/6004505/1028230, edited from count to place of nth count.
- public static int NthIndexOfCharInString(string strHaystack, char charNeedle, int intOccurrenceToFind)
- {
- int intReturn = -1;
- int count = 0;
- int n = 0;
- while ((n = strHaystack.IndexOf(charNeedle, n)) != -1 && count < intOccurrenceToFind)
- {
- n++;
- count++;
- }
- if (count == intOccurrenceToFind) intReturn = n;
- return intReturn;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement