Count instances of a character

I have a paragraph of text. I want to count the number of times there is a “*” in the text. It seems pretty simple but I just haven’t been able to figure it out. How do I do this?

For instance:
should return 4

Any help would be much appreciated.

Hi. Welcome to MacScripter.

You can count how many blocks of text there are around the asterisks and subtract 1! This works even when the asterisks are together or at the ends of the text.

set theText to "ABC*ABF**ASDASD*AS"

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "*"
set asteriskCount to (count theText's text items) - 1
set AppleScript's text item delimiters to astid

return asteriskCount

With your input text and AppleScript’s text item delimiters set to “*”, the ‘text items’ of the text are {“ABC”, “ABF”, “”, “ASDASD”, “AS”}.

Thank you so much…that was easy