# How to double single quote (beginner blockage)

**URL:** <https://www.ruby-forum.com/t/how-to-double-single-quote-beginner-blockage/52741>\
**Category:** Ruby\
**Created:** [January 18, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/how-to-double-single-quote-beginner-blockage/52741 "2006-01-18T16:26:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandru\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@Alexandru\_P](https://www.ruby-forum.com/u/Alexandru_P)\
**Post date:** [January 18, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/how-to-double-single-quote-beginner-blockage/52741/1 "2006-01-18T16:26:24Z")

</div>

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:

```auto
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
