oder mal anders
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sub str_replace {
my ($string, $pattern, $replace) = @_;
$pattern ||= "";
$replace ||= "";
my $patternlen = length $pattern;
my $replacelen = length $replace;
my $pos = 0;
while(($pos = index($string, $pattern, $pos)) > -1) {
$string = substr($string, 0, $pos) . $replace . substr($string, $pos + $patternlen);
$pos += $replacelen;
}
return $string;
}
str_replace("abcdefghijk", "cde", "");
aber nimm ronnies vorschlag!