Thread regex stringteil löschen: tüdelü (2 answers)
Opened by rio at 2005-07-01 20:24

esskar
 2005-07-01 21:49
#5163 #5163
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
oder mal anders
Code: (dl )
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!

View full thread regex stringteil löschen: tüdelü