5% assure discount from here only

Tuesday, January 25, 2011

(9) How to count the number of occurrences of a substring within a string?

Solution :

$string = "-9 55 48 -2 23 -76 4 14 -44";
while ($string =~ /-\d+/g) {
$count++;
}
print "There are $count negative numbers in the string";

No comments:

Post a Comment