Skip to main content
Question

String Replace with Conditional Mapping


hi experts

 

 

do you know if the string replacer can be used with conditional mapping to replace multiple strings  instead of using a few string replacers ?

 

 

i tried a few options but havent got it working 

 

 

appreciate your help and suggestions 

5 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • October 8, 2014
Hi,

 

 

Could you please post some examples which describe what you need to do?

 

I'm guessing that the StringReplacer with regular expression, or the StringPairReplacer help you.

 

 

Takashi

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • October 8, 2014
For multiples you can just use a creator and tcl regsub function.

 

 

 


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • October 9, 2014
Or u can also use

 

 a creator with [string map {mappingpairs} string ]

 

 

Here is one to clean "bad" language....;)

 

 

 

 

..if this is what u meant.

 


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • October 9, 2014
@Gio, recently I have been exploring "<FME HOME>/transformers/fmesuite.fmx".

 

If you peek at the file, you can see that many transformers are implemented with Tcl commands, especially for string operations. The StringReplacer calls "regsub" and "string map"; the StringPairReplacer is a wrapper of "string map".

 

That's very interesting - the FME Internal :)

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • October 9, 2014
Yes, i was aware of that for a long time.

 

In some post David, i think it was David even mentioned that FEM uses a lot of tcl.

 

 

The implementations are limited compared to what one can do by using creators.

 

In the string class transformers regexp use is very limited, u cant do forward (positive nor negative) lookups, u cant use switches etc.etc.

 

In attributeCreators u can use almost the full range of tcl (i even have one that executes a .exe from within a creator..lol).

 

Also you can nest them (seammingly) indefinitely.

 

 

nesting: @Evaluate([lsort -unique [split {"@Value(text_line_data)"} {}]])

 

Wich makes the AttributeCreeator extremely powerfull.

 

 

Prior to conditionla merging, conditionalmerging was already possible...by using tcl.

 

 

The hard or convoluted bit is the need to use the @Evaluate() at correct moments in a tcl in an attributecreator...

 

 

input: "Hello/DearFmeCommunity"

 

 

tcl1:

 

@Evaluate([regsub -all {([a-z])/*([A-Z])} "@Value(tststr)" {\\1@Evaluate(@Evaluate([regexp -all {[a-z](/+)[A-Z]} "@Value(tststr)" M m])==1?",":"" "")\\2}])

 

 

output:

 

Hello,Dear,Fme,Community

 

 

 

I have some that are truly unreadable...lol.

 

 

 

I made a couple of scripts in this forum showing this.

 

This is on the forum somewhere, about reading data out of a html fragment:

 

 

 

 

 

=[string range {@Value(html_txt)} [expr [lindex [lindex "@Value(tags_idxs)"  @Value(Ind)] 0] +1] [expr [lindex [lindex "@Value(tags_idxs)"  @Value(Ind)] 1]-1]]

 

 

 

Also tcl allows one to add missing FME transformers like

 

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings