Re: find out how many times particular character occur in given string.

From: Radoulov, Dimitre <cichomitiko_at_gmail.com>
Date: Thu, 11 Dec 2008 13:30:00 +0100
Message-ID: <ghr14i$go6$1@reader.motzarella.org>


Mladen Gogala wrote:
> On Wed, 10 Dec 2008 05:19:20 -0800, Sanjeev wrote:
>

>> Dear Gurus,
>>
>>   I want to find out how many times particular character occur in
>> given string.
>>   e.g. 'A*B*C*D*E*F' count of '*' is 5
>>          'A*B*C*D' count of '*' is 3
>>          'A' count of '*' is 0

[...]
>
> You can also do that in Perl:
>
> perl -e '$a="A*B*C*D*E*F"; print scalar(split(/\*/,$a))-1,"\n";'
[...]

Or even:

perl -le'print shift=~tr/*//' 'A*B*C*D*E*F'

Regards
Dimitre Received on Thu Dec 11 2008 - 06:30:00 CST

Original text of this message