6 Einträge, 1 Seite |
Quote\n\nindex STR,SUBSTR,POSITION
index STR,SUBSTR
The index function searches for one string within
another, but without the wildcard-like behavior of
a full regular-expression pattern match. It
returns the position of the first occurrence of
SUBSTR in STR at or after POSITION. If POSITION
is omitted, starts searching from the beginning of
the string. The return value is based at 0 (or
whatever you've set the $[ variable to--but don't
do that). If the substring is not found, returns
one less than the base, ordinarily "-1".
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sub indexex
{
my ($str, $substr, $position) = @_;
my $start = $position || 0;
my $len = length $str;
my $sublen = length $substr;
my @retval = ();
return @retval unless $sublen;
while($start + $sublen < $len)
{
if(substr($str, $start, $sublen))
{
push @retval, $start;
}
$start++;
}
return @retval;
}
my @wort1 = split //, $erstes_wort;
6 Einträge, 1 Seite |