How to count occurrences of a specific character in a Google Sheets cell appearing last in the cell (and ignoring the other occurrences of the same character appearing before last in the cell)?
I'm trying the following:
If cell C1 contains a period (".") as the last character in the cell C1, then return 1 as a result, else (if cell C1 contains no period, or periods before the last character without any period as the last character in Cell C1) return 0 or blank or ignore.
I've tried this formula so far, but it returns 1 even when there's a period before the last character too :
=COUNTIF(C1,"*.*")
Following this tutorial:
- https://www.quora.com/Which-Google-Sheets-function-allows-you-to-count-the-frequency-of-occurrence-of-a-certain-string-of-characters-in-a-given-column
- https://docs.google.com/spreadsheets/d/1DsHE-TaFNVno3FoKipy1JgFEN8s4mVAWzRnbtKy2mNs/edit#gid=0
Here's a screenshot of the result I get:
I've also tried to add space at the end of the criterion, but it then ignores it:
=COUNTIF(C1,"*.*")
Here's a screenshot of the 2nd result I get:
What I would like as a result would be:
- Help. Help. (1) (counts the occurrence of the last "." only)
- Help. Help (0) (ignore count)
- Help. (1)
Where the counting criterion would be specific to the last character, and the last character being a period (".")
EDIT:
I also had a look at this about the =RIGHT
function and it got me thinking:
How do I get the last character of a string using an Excel function?
I came up with this and it seems to work as well:
=IF(RIGHT(C1, 1)=".","1","")
to return a string ("1")
or
=IF(RIGHT(C1, 1)=".", 1, 0)
(for numerical value return of 1 and 0)
Finally I added how to select these characters as well as last characters too, with the help of the OR operator that way:
("!") ("?") ("...") ("—")
=IF(OR(RIGHT(C1, 1)=".",RIGHT(C1, 1)="!",RIGHT(C1, 1)="?",RIGHT(C1, 1)="...",RIGHT(C1, 1)="—"),1,"")