I have a method to import data from any CSV file. One must first define the parameters to recognise records and fields. To chose the record separator I have made a value list with two possible choices, LF (\n) or CR (\r\n)
//valuelist
Unix LF|\n
Windows CR|\r\n
The selected value is then passed to the method to convert the string to an array using function .split(separator,limit)
//var recSep contains value from valuelist
//var csvTxt contains string from csv file
var arrCsv = new Array();
arrCsv = csvTxt.split(recSep);
The problem is that the method doesn’t seem to recognise the record separator when this is generated by the value list, while it works if I substitute the variable with a string or with another variable not initiated by the value list. At first I thought it was a problem with the escape character: so I added one, two and three slashes in front of “\n”. But I always get odd results. I found an easy workaround by passing ‘LF’ or ‘CR’ from the value list triggering a method firing the relevant .split metod. But i am just curious to understand why the first metod doesn’t work. Thank you for any help.