开发者

Ruby: is there a simple one liner for replacing part of a string between two indexes with another string?

Lets say I have:

a = "Stack Overflow"

Is there a function where I can do something like:

> a.replace!(3, 10, " hello ")
> a
=> "Sta hello flow"

or so开发者_开发百科mething similar?

basically, said function I don't know of would remove all text inbetween the specified indexes, then insert the given text after the start index.


Try this:

a = "Stack Overflow"
a[3..9] = " hello "
a


Untested code:

a[3,10] = "hello" ?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜