Can I Get the Number of Specific Keyword in Variable?

Hello,
Can I get the number of a specific keyword in a variable? Example:

[Variable]
Line 1
aaaaaaaaBaaaaBaaaaaaaa eeeeBeeeeeBeeeeeeeeeee
Line 2
aaaaBaaaaaaaaaaaaaaaaa eeeeeeeeBeeeeeeeeeeeee

The total number of 'B's in this variable is 6. And when only before 'Line 2', it's 4.
I would like to get those numbers. Can I? If yes, how?

Thanks in advance for your help.

Kyu

Here's one way to do this using the For Each action. You can modify the action in blue to set the keyword you want to look for:

Count Keywords in Variable (Per-Line and Total).kmmacros (5.9 KB)
image

Results
53%20AM

In your example you used a single character as the keyword. I will presume that's always what you want. If that's not what you wanted, this solution would have to be modified. Here's how I would do it, in a single action:

image

There's definitely a chance that I misinterpreted what you wanted. But if I did, I can probably modify this example to make it work for you.

Of course you can use a variable in place of the Text in my example. I just thought it was easier to illustrate this way.