public static class StringEx { public static int LastIndexOfWithMax( this string str, char c, int maxChars ) { var strEnd = str.Length - 1; if( strEnd < 2 ) return -1; for( int i = strEnd; i >= 0; i-- ) { if( str[i] == c ) { return i; } } return -1; } }