On Mon, Sep 24, 2012 at 2:28 PM, Geena Tho <[email protected]> wrote:
> Thank you Wayne, But
>
> (0..n-1).each do |i|
> st.insert(i,ch)
> end
> This is my code, st is my string. I need to insert a character, say ch.
> n is 3
>
> for example, if st = 'ab' and ch = 'c' i get:
> abc
> aabc
> aaabc
> But the desired output is
> abc
> bac
> bca
The last two outputs have order of "a" and "b" reversed - that can
never be the result of simply inserting something into "ab". Are
those typos or is it intentional? If it is intentional, what is it
that you _really_ want?
In case of type, please have a look:
irb(main):001:0> st = 'ab'
=> "ab"
irb(main):002:0> ch = 'c'
=> "c"
irb(main):003:0> 3.times {|i| puts st.dup.insert(i, ch)}
cab
acb
abc
=> 3
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en