One thing at a time all the time!

Welcome to Rocteur
Thursday, April 25 2024 @ 02:41 PM CEST

How do I count the number of times a character appears in string ?

If you're interested in counting the number of times that a particular
character occurs in a string, the tr/// operator is probably what you
want.

my $some_string = q{This isn't a 'test'.};
my $count = ($some_string =~ tr/'/'/);

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

FAQ Manager » Perl » How do I count the number of times a character appears in string ?