Question

How to use string padder in FME to specify pad width based on each field value for different field's to have leading spaces ?


Badge +1
Hi All,

 

  1. I have designed a workbench in which i will pass an input field to StringLengthCalculator transformer and the result is stored in a default attribute (_length).
  2. Then, i have passed this (_length attribute) to ExpressionEvaluator  transformer to calculate values based on this formula                                (13 - @value(_length))+ @value(_length) and the resultant value is stored in default attribute (_result)
  3. This _result attribute is mapped to pad width parameter of StringPadder transformer and a particular field is selected in it which needs to be updated in target.
  4. I can see the trailing spaces on the target field to the left.

 

But, my main challenge is how to perform this flow on all fields because we cannot give uniform pad width to all fields and pad width shoulddepend on the stringlength of different field values in source table and all the target fields should have different number of trailing spaces based on their source string value.

 

 

Kindly provide me some idea ? :)

 


3 replies

Userlevel 4
Badge +13
Hi.

 

 

Maybr the following my help

 

http://fmestore.safe.com/transformers/StringLengthFormatter.htm
Badge +1
Thanks Itay. String Formatters works!
Userlevel 2
Badge +17
Hi Seeni,

 

 

If many different fields should be treated simultaneously, I would use the PythonCaller with a script like:

 

---

 

import fmeobjects   # Target field names TARGETS = set(['attr1', 'attr2', 'attr3'])   def paddingLeft(feature):     for name in feature.getAllAttributeNames():         if name in TARGETS:             s = str(feature.getAttribute(name))             # Calculate padding size. Modify appropriately.             n = 13 - len(s)             if 0 < n: feature.setAttribute(name, (n * ' ' + s)) ---

 

Takashi

Reply