[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: use reqex to get the middle character and repeat it

Dan Diebolt

3/14/2008 12:56:00 AM

[Note: parts of this message were removed to make it a legal post.]

>string will always be 3 chars long

If the string is always 3 chars long you could simply do this

str[0..0] + str[1..1] *4 + str[2..2]

or this

str[0].chr + str[1].chr * 4 + str[2].chr


1 Answer

Mathijs

3/14/2008 11:26:00 AM

0

Dan Diebolt schreef:
> [Note: parts of this message were removed to make it a legal post.]
>
>> string will always be 3 chars long
>
> If the string is always 3 chars long you could simply do this
>
> str[0..0] + str[1..1] *4 + str[2..2]
>
> or this
>
> str[0].chr + str[1].chr * 4 + str[2].chr
>
>

or this... str[1,1]=str[1,1]*4