Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Answer: How do I insert characters at certain positions in a string?

( #291981=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How do I insert characters at certain positions in a string? contributed by Anonymous Monk

If you do not want to replace the character you can set the substring length to zero.
my $padded = 'ABCDEFG'; substr($padded, 2, 0) = '1'; substr($padded, 1, 0) = '2';
This will result in 'A2B1CDEFG'

Comment on Answer: How do I insert characters at certain positions in a string?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (16)
As of 2015-07-03 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls