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:
The desired out put would be "This_is_my_string"
$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"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: string manipulation
by indigo (Scribe) on Mar 29, 2001 at 22:43 UTC | |
by indapa (Monk) on Mar 30, 2001 at 00:59 UTC | |
(tye)Re: string manipulation
by tye (Sage) on Mar 29, 2001 at 23:35 UTC | |
Re: string manipulation
by Xxaxx (Monk) on Mar 30, 2001 at 00:57 UTC | |
Re: string manipulation
by tune (Curate) on Mar 29, 2001 at 22:44 UTC | |
by Desdinova (Friar) on Mar 29, 2001 at 23:09 UTC | |
by Xxaxx (Monk) on Mar 30, 2001 at 01:15 UTC | |
by extremely (Priest) on Mar 30, 2001 at 03:31 UTC | |
by Xxaxx (Monk) on Mar 30, 2001 at 03:56 UTC | |
| |
by Desdinova (Friar) on Mar 30, 2001 at 03:57 UTC | |
Re (tilly) 1: string manipulation
by tilly (Archbishop) on Mar 30, 2001 at 04:33 UTC |
Back to
Seekers of Perl Wisdom