Note that tr/// will work for unicode strings, but for Inline::C to
do that more work will be necessary.
On Mon, Sep 03, 2007 at 17:42:12 +0300, Pinkhas Nisanov wrote:
> Hi,
>
> On 9/3/07, Amir E. Aharoni <[EMAIL PROTECTED]> wrote:
> > What is the best way to count the number of times that a character
> > appears in a string?
>
> if you need good performance, use "Inline::C".
> e.g.:
>
>
> use Inline C;
>
> print "Char in Str: ". chCnt( 'a', 'ajhajhhjajhjajh' ). "\n";
> ### you get:
> ### Char in Str: 4
>
> __DATA__
> __C__
>
> int chCnt ( char lookChar, char *str ) {
> char c;
> int i = 0;
> int currCnt = 0;
>
> while ( c = str[i++] )
> {
> if ( c == lookChar )
> {
> ++currCnt;
> }
> }
>
> return currCnt;
> }
> _______________________________________________
> Perl mailing list
> [email protected]
> http://perl.org.il/mailman/listinfo/perl
--
Yuval Kogman <[EMAIL PROTECTED]>
http://nothingmuch.woobling.org 0xEBD27418
_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl