Syntactic Confectionery Delight | |
PerlMonks |
string manipulationby parsifal (Novice) |
on Mar 29, 2001 at 22:39 UTC ( [id://68158]=perlquestion: print w/replies, xml ) | Need Help?? |
parsifal has asked for the wisdom of the Perl Monks concerning the following question:
I have a string and want to alter all the instances of a certain character within in it. Here is my feeble attempt: $instring = "This-is-my-string"; $outstring = ""; for ($i=0; $i length $instring; $i++) { if ($instring[$i] ne "-") { $outstring .= $instring[$i]; } else { # replace with a new character or substring $outstring .= "_"; } } print "$outstring"; The desired out put would be "This_is_my_string"
Back to
Seekers of Perl Wisdom
|
|