Skip to main content
Solved

String Pair Replacer inner workings

  • October 21, 2024
  • 1 reply
  • 105 views

pkno
Contributor
Forum|alt.badge.img+5
  • Contributor

Helly everyone,

I am working with data that consists of abrreviations/code items that are strung together in a single field which I am trying to convert to full text. For that I am using a string pair replacer which contains thousands of mapping pairs, but I have encountered a problem which I can’t seem to solve without knowing how exactly the String Pair replacer does its thing. The problem arises when multiple codes share letters.

 

Here`s an example: I have the following pairs somewhere in my replacement pair string

**gn green

**bn brown

g gravel

F mud

So F:**bn**gn should map to Mud:browngreen but whats happening is this: M:brown**gravelr.

I figured that the transformer probably checks its list from start to finish and ordered my list by string length in hopes it would transform longer strings first. The order of replacement items definetely has a big impact on the result and I was succesful of ironing out most errors in doing that but this particular translation and a few others still dont seems to be working correctly. 

Does anyone have any insight on how the transformer works and how I can solve this issue? I am pretty certain that this can be solved by ordering the replacement pairs in a certain way. 

Best regards 

 

Best answer by geomancer

String replacement is processed top down. As the documentation states:

Replacement is done in an ordered manner, so the key appearing first in the list will be checked first, and so on.

So if you want to replace **gn with green and g with gravel, the replacement of  **gn with green should occur before the replacement of g with gravel.

In the results of a replacement no further repacements will be done (so when **gn is replaced with green, the g in green will not be replaced with gravel.)

 

View original
Did this help you find an answer to your question?

1 reply

geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • Best Answer
  • October 21, 2024

String replacement is processed top down. As the documentation states:

Replacement is done in an ordered manner, so the key appearing first in the list will be checked first, and so on.

So if you want to replace **gn with green and g with gravel, the replacement of  **gn with green should occur before the replacement of g with gravel.

In the results of a replacement no further repacements will be done (so when **gn is replaced with green, the g in green will not be replaced with gravel.)

 


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