Question

Leading zeros

  • 20 November 2013
  • 7 replies
  • 42 views

Hi I need to end up with a column that looks like this

 

 

SDRC00001

 

SDRC00002

 

.....etc

 

the sequential numbers at the end of the string come from another column.

 

 

What transformer do I use for the leading zeros and how do I do it?

 

 

cheers,

7 replies

Badge +21
Use the Stringformatter on the last part ( 00001) with parameters 05s (creates a string with 5 integers putting zeros to the LEFT) 

 

 

Then use an AttributeCreator to merge the number (00001) with the text-attribute (SDRC)
Userlevel 4
Hi,

 

 

just as an alternative to the StringFormatter, you can also use the StringPadder. I sometimes find the results a bit more predictable.

 

 

David
Userlevel 2
Badge +17
Hi,

 

 

And also, PadLeft function from FME String Functions can be used in the AttributeCreator or the StringConcatenator. @Value(Prefix)@PadLeft(@Value(Number),5,0)

 

 

Here is a miserable cat to be skinned :-)

 

Takashi
Userlevel 4
Well, since we're going down that path, here's a solution for a PythonCaller :-)

 

 

def FeatureProcessor(feature):     attrib_to_trim = "MY_ATTRIBUTE"     pad_width = 10     pad_char = "0"     feature.setAttribute(attrib_to_trim,          str(feature.getAttribute(attrib_to_trim)).         rjust(pad_width, pad_char))

 

David
Badge +21
Haha, very good example of the fact that you can do the same thing 100 different ways with FME :). 
Userlevel 2
Badge +17
It's a great thing of FME that there are various approaches to do the same thing. Also enjoy a TclCaller. format {%s%05s} [FME_GetAttribute "Prefix"] [FME_GetAttribute "Number"]
Userlevel 4
Badge +13
poor cat ... ;)

Reply