Home > Software design >  How can I FIND the last instance of a character in a string? (Google Sheets)
How can I FIND the last instance of a character in a string? (Google Sheets)

Time:11-03

I need a Google Sheet function that will return the position of the last instance of a particular character. Basically, FIND, but starting on the right.

For example, for the data set below, I need to return the position of the last dash.

ABC-DEF-GHI = 8
ABCD-EF-GH-IJK = 11
AB-C-DE-FGH-I-JK = 14

Thanks!

I don't know where to start. MID might work, but the file names are of different lengths and different formats. The files just generally end with - ***.png, and I need the asterisk. The string I need is also of variable length and can contain spaces (the string is the name of the student).

CodePudding user response:

Here's a possible solution:

=len(regexextract(A1,".*-"))

It's essentially extracting everything up to the last dash and taking the length of the resulting string.

CodePudding user response:

for the whole array try:

=INDEX(LEN(REGEXEXTRACT(A1:A3; "(.*-)")))

enter image description here

  • Related