Skip to main content
I'm reading a file which is delimited by a space using the csv reader, some of the fields are enclosed in quotes (although this doesn't appear to be related to what type of data they contain).

 

 

If i read the file with the parameter strip quotes from fields set to no and then rewrite the file with quote output values set to no i get an error that a string value could not be converted to a float.

 

 

Any ideas on how to read this file and write it out again in the same format?
If i set all the column types in the writer to text I get something that looks about right but with the spaces that are not delimiters changed to |
Hi,

 

 

for the reader, try the PythonCreator solution I posted some time ago here.

 

 

It is, in certain particular scenarios, a bit more robust than the FME csv reader.

 

 

David
Hi,

 

 

Is there any particular reason for setting "no" to "Strip Quotes From Fields" on the CSV Reader? If yes, maybe solution will be different depending on the reason and actual data condition (there might be no solution).

 

If no, change it to "yes", and set "if_needed" to "Quote Output Values" on the CSV Writer.   When the separator is set to "space" and also "Quote Ouput Value" is set to "no", the CSV Writer seems to replace every white space in attribute values with | (pipe) automatically to distinguish the separator character.

 

 

Takashi
The file is not really a csv file so not all text fields are enclosed within quotes so the easiest way to ensure quotes appear around the same fields in the writer is to keep them as part of the field.

 

 

In the end I decided it was easiest just to set everything to text then use a find and replace in Notepad++ to change the | back to spaces.
I think the StringReplacer with these settings can be used. Text to Find: ^"[^"]*"([^"]*)"[^"]*"$ Replacement Text: \\1 Use Regular Expressions: yes   It will replace ""Mill Barn" Newboundmill Lane" with Mill Barn. If you specify "\\1" to Replacement Text, replaced string will be "Mill Barn" (quoted). When the attribute value doesn't match with the regular expression, it retains the original string (replacing will not be performed).   Hope this helps.

Reply