Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace characters of a string in specified position(s) 1

Status
Not open for further replies.

mikawin

Technical User
Apr 15, 2009
28
US
I want to replace characters in specified positions for a series of strings.

An arbitrary example:

String Input: XXXyRRRtF8
Replace 4th & 8th characters 'y' and 't' with '1' & '2' respectively to give the output: XXX1RRR2F8

Thanks for your help!

~Mika
 
One way:
Code:
$_ = 'XXXyRRRtF8';
substr($_,3,1,1);
substr($_,7,1,2);
print;
Which prints: XXX1RRR2F8
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top