A lot of double quotes in a string

Hello, I hope you are fine. I need to have a lot of double quotes in a string. How can I do this? I will give this string to system function or if we have better function I can use.
Best regards.

There are other syntax to create double quotes in a string:

  1. Use '...': Using single quotes is another way to wrap double quotes inside. Yo can do a = '"Once upon a time in a galaxy far far away" -Someone, "Some conference"'

  2. Use %(): Using %() syntax is another way. The () isn’t mandatory though. For example, a = %("Once upon a time in a galaxy far far away" -Someone, "Some conference")

  3. Use %Q(): Using %Q() syntax is another way, it’s just like %(). The () isn’t mandatory though. For example, a = %Q("Once upon a time in a galaxy far far away" -Someone, "Some conference")

  4. Use %q(): Using %q() syntax is yet another way. The () isn’t mandatory though. %q() doesn’t support string interpolation. For example, a = %q("Once upon a time in a galaxy far far away" -Someone, "Some conference")

  5. Heredocs: Ruby supports heredocs, you can do this in your string instead:

a = <<~HEREDOC.downcase
    "Once upon a time in a galaxy far far away" -Someone, "Some conference"
HEREDOC

During printing, you want to use puts instead of p. If you need to simply surround your string, you String#dump, but it will mess up with your string:

> puts "A string with emoji is a string".dump
"A string with emoji is a string"
=> nil

> puts "A string with 🐵 is a string".dump
"A string with \u{1F435} is a string"
=> nil

Hope this helps!

Thank you so much. I have a string like this;
cmd = ‘there are strings “(“also there are string”, “string”, “string” )”’’
is this correct?

Yes seem perfect.
cmd = 'there are strings "("also there are string", "string", "string" )"'

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