Skip to main content

Morning all,

 

I m trying to create a comma delimited .txt file wth quotes around any character type variables.  I can manage to either have quotes around all variables (characters & numerics) or none (using the "if needed" or "no" options), but i need to only have quotes around character fields.  Is there a way to get the "if needed" option to identify characters?

 

 

cheers

 

 

Yorkie  
Hi,

 

 

the CSV writer in FME will either:
  • never use quote characters (regardless of string contents)
  • always use quote characters (both for strings and numbers)
  • write quote characters "as needed", meaning it put quotation marks around any value that either contains the separator character or the quotation character
If you need something else, you will either have to implement it using StringConcatenators and a Text File writer, or using the python CSV module in a PythonCaller (here is a starting point).

 

 

Or you could write Safe support and ask nicely :-)

 

 

David

 

 


Hi Yorkie,

 

 

If fields which must be quoted are fixed, I would use a StringReplacer to quote them. Attributes: <select fields which must be quoted> Text to Find: ^(.*)$ Replacement Text: "\\1" Use Regular Expressions: yes You can then write features using the CSV Writer with "no" quote option.   If you need to determine whether individual attribute value is numeric representation, it's not impossible logically to use "AttributeClassifier + StringConcatenator or StringReplacer" for every field. However, when there are many fields, the workspace will be too cluttered. I think it cannot be avoid to write a script in order to prevent cluttering.   As David mentioned, Python csv module would be one possible way. If it's not suitable for your situation (e.g. when needing "fanout"), you will have to write a Python or Tcl script of several lines. I think that the script to determine and quote non-numeric values of specified fields would not be so complicated.   I hope an optional function for specifying condition(s) will be added to the StringReplacer.

 

 

Takashi
Many thanks for your answers.

 

 

My issue with FME here is that i have a table with a variable which can contain both characters and numerics, but because the first 100,000 records all contain numerics, some softwares assume that the variable is numeric, meaning the records containing a character entry are "invalid".  I don't however want to add quotes to all variables as i want the XY columns to remain numeric.

 

 

Looks like the simplest answer will be probably stick to exporting to CSV from MapInfo  

 

 

Thanks

 

 

Yorkie

 

 


Hi Takeshi,

 

 

Using your string replacer instructions adds the quotes at the beginning of the variables which is excellent.  Is there an equivalent instruction to place a quote at the end of the variable?

 

 

THanks

 

 

Yorkie  

 


I think this setting should work to append quotation marks to both side of the string.

 

Text to Find: ^(.*)$ Replacement Text: "\\1"   e.g. abc --> "abc"
Takashi - I just discovered your answer as I needed to do exactly the same thing as Yorkie. Perfect answer thanks. I'll note though that I initially had the same problem as Yorkie, you get a quote at the front of the resulting CSV value, but not the end. It did eventually dawn on me though that, after inspection I could see FME was adding a quote at both ends... I'd just not expanded the target attribute width to accomodate the extra 2 characters in width. Duh! A bit of an "idiotic eureka moment" that I will place here for other 'unfortunate souls' to find and avoid this simple pitfall...

Reply