CSV reader & delimiter as variable problems (bug?)

I wrote a small workflow to read a text file and determine the delimiter (from a list of delimiters). Then I foward the file name and the delimiter via variable to the CSV Reader.

This works fine for e.g. comma "," or semicolon ";", but doesn't seem to work for tab "\t". Also tried \\t even \\\t.

(the variable passed to colDelimiter are thus ,; or \t , without the quotes).

Does anyone have any ideas/suggestions, or is this a bug?

 

Using "\t" for a tab character only works if the node/piece of code processing this string knows about escape characters. If you have "\t" in a string cell, for example, it's simply "\t" and not a tab character. How exactly do you get to the tab character as delimiter?

I use the line reader to read 5 lines, count the number of commas, semicolons, tabs per row and compare (sort of like a dictionary comparison). see Picture. I also have a java based version doing essentially the same, see 2nd pic.

It's a bit oversimplified probably, but for my files I can be certain that this is consistent (enough). Then I write a string column with the corresponding delimiter and convert that to a variable for the csv reader.

I tried the file reader, but there you can't have the column delimiter as a variable?

So I did a bit more fiddling and found a "work-around". I use the Line Reader again to read the whole file, then use Cell Splitter where you have the setting "use as escape character". Only thing then is your column names end up as Row 0 and you need to extract them and fix column headers.

So, if the .csv file reader had the option "use as escape character" with the delimiter.... hint, hint :D

Hello Docminus,

There is a probably easier workaround:

Put a Java Edit Variable node between the Table Row to Variable and the CSV Reader node. In this node put a switch/if-statement.

if($${Scolumn1}$$.equals("\\t")) return "\t";

Not elegant, but does the job in one node.

Best,
Ferry

I use the File Reader node, which has a <tab> delimited option

1 Like