nit  i would have found this easier to read as i lastextensionstartindex apologies if i am being stupid  is the correct e g  i assume this is the kind of input you are trying to catch a b stuff b  is invalid  when i lastextensionstartindex isn t the check i lastextensionstartindex  or  i lastextensionstartindex 