Snatch any course you want for just $15! Go to “Courses” and find a course ↓
Introduction
CSV Files
4. Additional CSV rules
Summary

Instruction

Good job! Let's take a look at some additional CSV rules that are worth remembering.

manufacturer model remarks price
XYZ Ltd X56 basic model, good for most people 20000
TechLovers D5 30000
BigCorp 6080i luxurious, "fashionable", not released 80000
  1. The first product in the table contains a comma in the remarks column. But since commas are generally used as separators between fields, we need some way to mark the comma as part of the field and distinguish it from commas that are being used as separators. In such cases, we usually enclose the entire field in a pair of quotes. So it will look like this:
    XYZ Ltd,X56,"basic model, good for most people",20000
  2. The second product doesn't have any remarks. Even though the cell is empty, we still need to include it in the CSV file by placing two commas next to each other. This is because each row (line) in a CSV file must have the same number of fields (columns). So it will look like this:
    TechLovers,D5,,30000
  3. The third product uses a pair of quotes in the remarks column. In such a case, we need to do two things:
    1. Put the entire field inside a pair of quotes.
    2. Each time we want to introduce a quotation mark, double it.
    So it will look like this:
    BigCorp,6080i,"luxurious, ""fashionable"", not released",80000

With all of these combained, we will end up with:

manufacturer,model,remarks,price
XYZ Ltd,X56,"basic model, good for most people",20000
TechLovers,D5,,30000
BigCorp,6080i,"luxurious, ""fashionable"", not released",80000

Exercise

True or False: Answer by assigning True or False to the variable below the given statement.