Instr finds position but InstrRev does not - head melting - Stack Overflow

admin2025-04-16  3

I'm genuinely sorry for posting again, I was getting on so well reading and experimenting however this quirk between Instr and InstrRev has me stumped.

My string which was a web copy and paste and for some reason partially fails on sString = StrConv(sString, vbProperCase) is below but that's not the problem and only for reference.

Birth Of samuel Keenan in 1880

On that string if I perform

debug.Print InStr(1, sString, "In", vbTextCompare) after failure it returns 24 which is correct.

If I perform

debug.Print InStrRev(sString, "In", vbTextCompare) on that same string it returns ZERO which is wrong.

I'm trying to build other variables on text positions to extract the Given Name, Surname and Date from these strings. I used the vbTextCompare to overcome the case differences still resulting from the vbProperCase fail bit it's not working in InstrRev?

If I use debug.Print InStrRev(sString, "in") I get 24 which is correct but then I am snagged again by case variations.

I'm guessing this is the formatted web paste which I do want to lift a hyperlink from and I have discovered how to do that, a plain text paste would maybe work ok but the possibility of lifting the hyperlink would be lost to me.

I guess the simple question is why does InStrRev(sString, "in", vbTextCompare) fail when InStrRev(sString, "in") works but ignores case variants?

The actual code snippet which fails on the last line due to iPos2 not getting set is below, the If Instr test does result in > 1 as I stated previously

iOf = (InStr(sString, "Of") + 3) 'start of Given Name
    If InStr(1, sString, "On", vbTextCompare) > 1 Then iPos2 = (InStrRev(sString, "On", vbTextCompare))
    If InStr(1, sString, "In", vbTextCompare) > 1 Then iPos2 = (InStrRev(sString, "In", vbTextCompare))
    iPos1 = (InStrRev(sString, " ", (iPos2 - 2)) + 1) 'start of surname

Thank you all in advance, I have been at this trial and error for almost two hours and it's starting to melt me head.

转载请注明原文地址:http://anycun.com/QandA/1744792760a87695.html