Forum: Ruby Not a Ruby person but trying to help a newbie

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A9aa7c2d678af4e2f92de79b15c8b794?d=identicon&s=25 Cheryl Cepak (charlie2869)
on 2008-12-02 05:30
Hi there

I am a C++ person but trying to help a friend using Ruby.
He is supposed to ask for user input by using an index number to change
the letter of a word given, like say "dog".  So the user it asked to
enter the index number, lets say 0 is entered by the user, and he then
asks the user to put a new letter in (letter is a variable), then he
wants to change the index of 0 which is the "D" to a "C" (where c was
put in by the user).

Can anyone help with this?  How to do it please?

Cheryl
A9aa7c2d678af4e2f92de79b15c8b794?d=identicon&s=25 Cheryl Cepak (charlie2869)
on 2008-12-02 05:32
Cheryl Cepak wrote:
> Hi there
>
> I am a C++ person but trying to help a friend using Ruby.
> He is supposed to ask for user input by using an index number to change
> the letter of a word given, like say "dog".  So the user it asked to
> enter the index number, lets say 0 is entered by the user, and he then
> asks the user to put a new letter in (letter is a variable), then he
> wants to change the index of 0 which is the "D" to a "C" (where c was
> put in by the user).
>
> Can anyone help with this?  How to do it please?
>
> Cheryl

Here is what he has so far:

student_name  = 'John Wallace'
puts student_name + "'s WordWarp Game!"
require 'zlib'
dictionary = Zlib::GzipReader.open('words3-8.gz').read().split()
current_word = 'dog'
target_word   = 'cat'

puts
puts current_word.to_s + ' => ' + target_word.to_s

puts 'What is the index of the letter you wish to change?'
index = gets
puts 'What letter do you wish to insert?'
letter = gets
temp_word = current_word.clone()


puts temp_word
60c6b87c4cc2716c83a737e0ba2d3bc0?d=identicon&s=25 David Rio Deiros (Guest)
on 2008-12-02 06:56
(Received via mailing list)
On Tue  2.Dec'08 at 13:24:28 +0900, Cheryl Cepak wrote:
> I am a C++ person but trying to help a friend using Ruby.
> He is supposed to ask for user input by using an index number to change
> the letter of a word given, like say "dog".  So the user it asked to
> enter the index number, lets say 0 is entered by the user, and he then
> asks the user to put a new letter in (letter is a variable), then he
> wants to change the index of 0 which is the "D" to a "C" (where c was
> put in by the user).

my_str = "Dog"
p "Before: #{my_str}"

puts "Index?" ; i = Integer(gets)
puts "letter?"; c = gets.chomp

my_str[i] = c
puts "After: #{my_str}"

-drd
This topic is locked and can not be replied to.