how to get # of occurances of a character in a given string

M

Martien verbruggen

On Sun, 16 Sep 2007 11:22:57 -0000,
$str = "vijaya";

if my character is 'a' then it should get the number 2

And the actual question is:
how to get # of occurances of a character in a given string

which I has to get from the subject line.

One possible answer can be found in the perlop documentation, under the
tr/// operator.

my $count = $str =~ tr/a//;

Martien
 
J

John W. Krahn

$str = "vijaya";

if my character is 'a' then it should get the number 2

$ perl -le'
my $str = "vijaya";
my $count = $str =~ tr/a//;
print $count;
'
2


perldoc -q count


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top