Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Ruby text variable with \ inside

I need to create a db record with a column with this value

query = "booster pro 12\24 v" 

but this is what stored into db column.

"booster pro 12\u0014 v"

if I try with single-quoted I get

'booster pro 12\24 v' -> "booster pro 12\\24 v"

but If I use this, I got the correct string printed.

puts 'booster 12\24 v' -> booster 12\24 v
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If I try with single-quoted I get

'booster pro 12\24 v' -> "booster pro 12\\24 v"

This is correct. You've already got the right answer.

A backslash is an escape character. When displaying escape characters in a double-quoted string, you must escape them with a backslash. That means a literal backslash is represented by two backslashes.

Two literal backslashes would be represented by four backslashes, in a double-quoted string.

Or for example, consider:

  • How would you display a newline character? Answer: "\n"
  • How would you display a backslash character, followed by an "n"? Answer: "\\n"

This behaviour is not specific to ruby.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!