From: Alexandru Popescu Date: 2006-01-19T00:27:46+09:00 Subject: Re: how to double single quote (beginner blockage) #: Jules Jacobs changed the world a bit at a time by saying (astral date: 1/18/2006 5:05 PM) :# > And what if the input string correctly contains double quotes?? ;-) > > String doesn't have a each_with_index method. > > class String > def each_with_index > counter = 0 > each_byte do |char| > yield char, counter > counter += 1 > end > end > end > > "abc".each_with_index do |char, index| > puts char.chr + ' ' + index.to_s > end > > Please note that char is an integer, so you have to call char.chr. > > Untested, but it should work. > I have passed over my no-brainer moment: [code] fixed_value = "" idx = 0 while (idx < wrong_value.size) do fixed_value << wrong_value[idx] if ( wrong_value[idx] == 39 ) if ( (wrong_value[idx + 1] != 39) ) if ( idx > 0 && wrong_value[idx - 1] != 39 ) fixed_value << '\'' end end end idx += 1 end [/code] but now i've reached the no-ruby point. Can you teach me what would be the ruby way? Note: the double quotes are not considered in this problem; in fact i am removing them right from the beginning ./alex -- .w( the_mindstorm )p.