moh19814
moh19814

Reputation: 147

ruby on rails replace single-quotes with double-quote in a string

I am trying to replace a single-quote with double quotes inside a string, as following:

current_res = 25
lowest_res = 15
str = "The result of the child is '#{current_res}' and the lowest grade is '#{lowest_res }'."

I need the output to look like:

str = The result of the child is "25" and the lowest grade is "15".

I tried different method using gsub but nothing work so far. Any ideas?

Upvotes: 0

Views: 1341

Answers (1)

Farhad Ajaz
Farhad Ajaz

Reputation: 274

If that's the only case you're covering where you need to show some output in double quoted string then. How about something simple like following

str = "The result of the child is \"#{current_res}\" and the lowest grade is \"#{lowest_res }\" ."

You can escape quotes in double quoted strings.

Upvotes: 1

Related Questions