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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split function 2

Status
Not open for further replies.

stevio

Vendor
Jul 24, 2002
78
AU
Have simple piece of code
Code:
$string = "1234";
@val = join(':',split(//,$string,2));
print @val;
__RESULT__

1:234

How can I get the result like 12:34 instead using the join function?

Is the only way to do this?
Code:
@val = split (//,$string);
print $val[0].$val[1].":".$val[2].$val[3];
 
Why would you want to do that using split? If you know the string is alway four digits there are better options, unpack() and substr() or s/// regexp like feherke sh

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Well, I'm bored:

Code:
$string = "1234";
substr $string,2,0,':';
print $string;


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top