How to change letter on some position in the string?

G

Guest

How to change letter on some position in the string?

eg.
$word="This is my test string."

Change letter on 7 nth position to "X"

$word="This iX my test string."

Or change letter on 15 nth position to "?"

$word="This is my tes? string."

Thanks.
 
J

John W. Krahn

How to change letter on some position in the string?

eg.
$word="This is my test string."

Change letter on 7 nth position to "X"

$word="This iX my test string."

$ perl -le'
my $word = "This is my test string.";
print $word;
substr $word, 6, 1, "X";
print $word;
'
This is my test string.
This iX my test string.

Or change letter on 15 nth position to "?"

$word="This is my tes? string."

$ perl -le'
my $word = "This is my test string.";
print $word;
substr $word, 14, 1, "?";
print $word;
'
This is my test string.
This is my tes? string.




John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top