If you have the reading and writing part done, I'd suggest:
- 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.
- In an AttributeCreator you can use the Arithmetic Editor to increase the number part by 1. Conversion to number should be automatic.
- Pad the number part back to a string of the correct length with a StringPadder.
- 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:
Â
- StringSearcher with the regular expression "(.*)(...)$" to split the value into the last three characters and the prefix
- ExpressionEvaluator with "@Value(_matched_parts{1})+1" to increment the suffix
- StringFormatter with "03d" to force the result to 3 characters
- 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.
Â