Is there a method to find the last occurrence of a character in a string?
edit: duh… never mind. Can’t read.
If I remember correctly, Kem’s M_String module has an InStrReverse function.
Kem will give you the RegEx for it, but if you want to go oldschool quick and dirty, CountFields/NthField will do it.
dim c as string = theCharacter
dim s as string = theStringToSearch
dim position as integer
position = len(s) - len(NthField(s, c, CountFields(s, c))) - 1
You may need to adjust by 1 to get the absolute correct value. (Ie., not tested)
Tested:
position = len(s) - len(NthField(s, c, CountFields(s, c)))
The pattern would be something like…
a(?=[^a]*)
…where the character in question is “a”. Just remember that RegEx gives you byte position, not character position.
Thanks all! Hi Kem long time no see.