Skip to main content
Gathering Interest

Improve StringReplacer to allow Multiple String Replacements

Related products:Transformers

takashi
Contributor
For example, if you need to replace suffix {a, b, c} with {x, y, z}, you will have to use three StringReplacers with different regular expressions. In this example, the StringPairReplacer cannot be used since the source string contains a, b, c within the non-suffix part.
sourcedestination
1abcaabcx
2abcbabcy
3abccabcz
I think the StringReplacer has a room to improve to allow users to define one or more replacement rules. Probably the parameters setting for the above example looks like this.
If the user defined two or more replacement rules, the transformer performs every replacement in the order from top to bottom.

11 replies

jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • January 29, 2016

Two other potential improvements:

 

 

Allow the stringReplacer to use List Attributes directly.

 

 

Optionally return an attribute with statistics (3 replacements were made)

 


mark2atsafe
Safer
Forum|alt.badge.img+43
  • Safer
  • February 7, 2016

Have you tried using conditional values here?

For example, using takashi's scenario, you should be able to replace the StringReplacers with a single AttributeManager. The value is set to conditional (eg if attribute ends-in a) and uses a regex function in the text editor (@ReplaceRegEx(attribute,$a,x))

See this example:

https://www.dropbox.com/s/oahudexz43imgva/LastCharacterMapper.fmw?dl=0


fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • February 9, 2016

Filed as PR 68066


Forum|alt.badge.img+2
  • February 20, 2017

@takashi Do you know of any other applications that offer this type of functionality that we could use as a

 


setld_solutions
Contributor
Forum|alt.badge.img+7

Hoping this will allow spreadsheet / table import, also. Thanks!


jackyd
Contributor
Forum|alt.badge.img+10
  • Contributor
  • March 15, 2020

This is great if your attribute only meets one of the conditions, what about if your attribute meets 2 or more conditions?


mark2atsafe
Safer
Forum|alt.badge.img+43
  • Safer
  • March 16, 2020

You can set up conditions to be AND or OR statements (or a mix of both) so you can hopefully use those to set up multiple conditions in any way you need. The first condition that is met, is the one that applies, so if you want to apply more than one result, then you'd need to use a separate line in the AttributeManager, or use a series of transformers.


gabriel_hirsch
Contributor
Forum|alt.badge.img+11

A small improvement with the StringPairReplacer would be to be able to use an attribute for Replacement Pairs


ecthelion
Contributor
Forum|alt.badge.img+12
  • Contributor
  • June 28, 2022

This would be so useful - I quite often look for other solutions than using multiple StringReplacers.


pradip
Participant
Forum|alt.badge.img+2
  • Participant
  • June 21, 2023

@Takashi Iijima​ Thanks for sharing an idea. I tried creating a custom transformer for it.

Hope this works !

https://hub.safe.com/publishers/spatial-kat/templates/stringreplacer_multiple


LizAtSafe
Safer
Forum|alt.badge.img+15
  • Safer
  • February 13, 2025
OpenGathering Interest

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