1: sub count_occurrences{
2: my($part, $whole, $cs)=@_;
3:
4: # $part -- the text you're searching for
5: # $whole - the string within you're searching
6: # $cs -- case sensitive? 1=yes, 0=no (may be omitted for non cs search)
7:
8: my($count)=0;
9: my($null)="\0";
10: if($cs==1){
11: while($whole=~/$part/s){
12: $count++;
13: $whole=~s/$part/$null/;
14: }
15: }else{
16: while($whole=~/$part/is){
17: $count++;
18: $whole=~s/$part/$null/i;
19: }
20: }
21: return $count;
22: }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Count String Occurrences
by nate (Monk) on Mar 24, 2000 at 10:49 UTC | |
by japhy (Canon) on Mar 28, 2000 at 09:35 UTC | |
by chromatic (Archbishop) on Mar 24, 2000 at 19:15 UTC | |
by Lee (Initiate) on Mar 24, 2000 at 22:31 UTC | |
by chromatic (Archbishop) on Mar 24, 2000 at 22:59 UTC |