By default in the CSV-files a comma is used as a separator for the fields.
In some instances however, it is more convenient to use another separator (for example, a semicolon, if the data often contains text with commas).
In this recipe we will consider changing the separators in the given CSV files.
First of all, let's create a file and a script, which will be working with customizations by default:
C:data.csv
with the following content:id,First,Last 1,John,Doe 2,Jane,Smith
function testCSVDelimiter() { var data = DDT.CSVDriver("c:\data.csv"); while(!data.EOF()) { Log.Message(data.Value("First"), data.Value("Last")); data.Next(); } DDT.CloseDriver(data.Name); }
In order to have TestComplete read out the data that are separated by semicolon, it is necessary to complete the following actions:
C:data.csv
by changing commas to semicolons:id;First;Last 1;John;Doe 2;Jane;Smith
C:schema.ini
file with the following content:[data.csv] Format=Delimited(;)
testCSVDelimiter
function. In the result, the function will correctly read all the data, pre-separated by semicolon instead of the comma.The file schema.ini
is an ordinary INI
file, which contains various parameters for CSV files in the same folder, where it is to be found. As a name of the section, the name of the file is used, and then their values are signified also. For example, in our case, we have denoted that data is to be separated by semicolon (the parameter Format=Delimited(;)
).
This file can contain settings for several files that are to be found in the same catalogue.
Apart from the data separators, the schema.ini
file can contain many more customizations (whether the file contains headings of the columns, the text encoding, data types for each of the columns, and so on). Reading up in greater detail about these settings is possible via the following link: http://msdn.microsoft.com/en-us/library/ms709353.aspx.