Show inches when I export CSV with ruby

Hello,

I am trying to add inches to my CSV description column and can’t get it to work.

When I add the double quotes, the code runs, but the quotes don’t show

Here is the code:

accounts = [
  { Product: "211STUD" , Quantity: 82, UOM: "ea" , Description: "2X6X104 5/8 SPR STUD KD" , Price: 22 },
  { Product: "2226S" , Quantity: 6, UOM: "ea" , Description: "2X6-16' #2 & BTR SPR KD" , Price: 33},
  { Product: "LVL2012-LF" , Quantity: 68, UOM: "lf" , Description: "LVL 2.0E 1 3/4"" X 9 1/2"" LINEAL FEET" , Price: 44.25 }
]

require 'csv'

CSV.open("testMyCsv.csv", "w") do |csv|
  csv << ["Product", "Quantity", "UOM", "Description", "Price"]
  accounts.each do |acc|
    csv << [acc[:Product], acc[:Quantity], acc[:UOM], acc[:Description], acc[:Price]]
  end
end

It should result with
LVL 2.0E 1 3/4" X 9 1/2" LINEAL FEET

:thinking: Perhaps to insert characters that are illegal in a string, you must use an escape character.
use an escape character : a backslash \ followed by the character you want to insert.

"LVL 2.0E 1 3/4\" X 9 1/2\" LINEAL FEET" 
1 Like

Yes, that works,

Thanks

… or use a single-quoted string literal.

Read about String Literal expressions: