nikitin
asked on
string manipulation
hello experts!
how do i insert a '<br>' every 24th character in a string?
how do i insert a '<br>' every 24th character in a string?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks
cidaris
$oldstring = "1234567890123456789012345
my @newstring = split(//,$oldstring,-1);
print "@newstring\n";
print "$newstring[5]\n";
print "$newstring[24]\n";
for (my $intX = 0; $newstring[$intX] ne ""; $intX++){
if (($intX != 0) && ($intX % 24 == 0)){
# character is not 0 and is a multiple of 24
$char = "\<br\>" . "$newstring[$intX]";
}
else {
$char = "$newstring[$intX]";
}
$out_string = $out_string . $char;
}
print "$out_string\n";