How to double single quote (beginner blockage)

Hi!

Sorry for this `stupid´ question but it looks like i am suffering a
mental blockage:

if I have a string that contains single quote (f.e. “al’alamein”) i
would like to escape it with
another single quote (=> “al’'alamein”).

there are cases when these strings are already escaped according to the
above rule, so those should
remain untouched

my `brainless´ attempt was:

fixed_value = ""
wrong_value.each_with_index do |char, idx|
	fixed_value << char
        	if ( (idx < wrong_value.size - 1)  && (wrong_value[idx + 1] != 
'\'') && (idx > 0) &&
(wrong_value[idx - 1] != '\''))
                	fixed_value << '\''
        	end
end

but the above results in exactly the same strings. I would appreciate
very much your help

./alex

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs