Skip to main content
I am trying to build a workspace that takes an attribute and trim it on a number of characters, increase part by 1 then rebuild the result and place in a new attribute.

 

 

i.e. I have a spreadsheet that has two collums A (source ref) and B (destination ref).

 

In A I have a ref such as 4VK012 I want to take the last three digits add 1 to it and then join it back to the rest of the attribute into collum B.

 

 

A                B

 

4VK012      4VK013

 

 

The prefix could be 2, 3 or 4 characters bt it always has 3 digits at the end.

 

 

Any ideas how I ca do this?

 

 

Thanks

 

seb
If you have the reading and writing part done, I'd suggest:
  1. Split the attributes into the front part and the number part, using a SubstringExtractor. You can use negative indices to specify length from the end.
  2. In an AttributeCreator you can use the Arithmetic Editor to increase the number part by 1. Conversion to number should be automatic.
  3. Pad the number part back to a string of the correct length with a StringPadder.
  4. Combine the two parts back into one with a StringConcatenator (or AttributeCreator).
Not tested this, but that's what I would try.
Hi,

 

 

here is one possible solution:

 

  1. StringSearcher with the regular expression "(.*)(...)$" to split the value into the last three characters and the prefix
  2. ExpressionEvaluator with "@Value(_matched_parts{1})+1" to increment the suffix
  3. StringFormatter with "03d" to force the result to 3 characters
  4. StringConcatenator with "@Value(_matched_parts{0})@Value(incremented)" to join the prefix with the new suffix
Test:

 

4VLK011 -> 4VLK012

 

4VK011 -> 4VK012

 

 

David
Hi Seb, 

 

 

There are a few challenges in here to overcome:

 

1) Once split you'll need to make sure the numeric part is completely numeric, a regex looking for say sA-Z] will help here.

 

2) The ExpressionEvaluator doesn't like numbers padded with zeros. There may be a formula to deal with this but the AttributeTrimmer is just as good, so test for these values first, increment them and then use the StringPadder to add the extra prefixes.

 

 

Best of luck, Dave
An experiment with FME functions: just one AttributeCreator with the following expression completes the job. Very interesting but maybe not practical...

 

@ReplaceRegEx(@Value(AttrName),(.*)((0-9]{3}),\\1)@Format(%03d,@Evaluate(@int(@ReplaceRegEx(@Value(AttrName),(.*)((0-9]{3}),\\2))+1))

 

 

Takashi
Hi Dave,

 

 

thanks for the heads up regarding the leading zero and the ExpressionEvaluator, I had forgot about that.

 

 

However, if you explicitely cast the input value as an integer, it works. Example / correction based on my suggestion below:

 

 

@int(@Value(_matched_parts{1}))+1

 

 

Given input 0123 the result is124, as expected. That way you don't have to use an AttributeTrimmer.

 

 

David
Sorry, didnt realize pasting the transformer would lead to such a load of text....

 

 

So i repost the last bit.

 

 

 A single attribute creator with a single line Tcl!

 

(mind u, building the Tcl is kinda hellish)

 

 

 

Insert a attributecreator and make attributename B

 

and value (using Arithmic editor):

 

 

/ scan  string repeat "0" @Evaluate(3-@string length @Evaluate(@Evaluate(eregexp {(e0-9]{3})$} "@Value(A)" matched cellA])?h scan $matched %d]+1 :"Leeg")]) ] %s])@Evaluate(@Evaluate(eregexp {(e0-9]{3})$} "@Value(A)" matched cellA])?h scan $matched %d]+1 :"No3DigitsFound"

 

 

The Value should start with a "=" (i think that happens automaticaly, sometimes a bit annoyingly)

 

 

I did this in FME 2012

 

(I used a sample excelsheet with attributename A and a bunch of testvalues as input)

 

 

@mr.Takashi: i cant find the ReplaceRegEx command in the Tcl manuals.
Hi Gio,

 

 

> @mr.Takashi: i cant find the ReplaceRegEx command in the Tcl manuals.

 

 

Recently, I found the ReaplaceRegEx function. It appears under 'FME String Functions' column of 'Advanced Text Editor' - FME 2013.

 

http://docs.safe.com/fme/html/FME_Transformers/Default.htm#transformer_parameters/advanced_text_editor.htm

 

  Here is descriptions about FME String Functions.

 

http://docs.safe.com/fme/html/FME_Transformers/Default.htm#transformer_parameters/StringFunctions.htm

 

I'm not familiar with Tcl, so I cannot say whether this function is related to a Tcl command.

 

 

Takashi
@mr.Takashi.

 

 

 

It is the string replace function in Tcl.

 

 

Been playing alot with FME for 3 years now, due to my work.

 

 

Lots of data and spatialdata analysis. Loving it!

 

Last 5-6 months im discovering the beauty of Tcl in Fme transformers. Great for making clean flows and less cluttering.

 

 

only thing i find bit annoying is the amount of @Evaluate calls needed when making complex Tcl in FME-creators, tester etc.

 


Reply