Clumsy replace

Hi,

I have a column “Var” with rows containing strings of the pattern “foo_bar”. “foo” and ”bar” are of variable lengths and I want to retain only the “bar”-part. I couldn’t find a way to replace “foo_“ with ”nothing” (in a filter?). :wink:

Now I have a custom transformation

mid(Var, search(Var, '_', 1)+1, length(Var)-search(Var, '_', 1))

which is working but ugly. Is there are more elegant setup?

Hi Helmut,

The most straight way is to do a simple ‘Filter’ action in the data wizard. Replace ‘foo_bar’ for ‘bar’. Is there a reason you might need to use a custom transformation?

For a custom transformation, in your case you can also use

replace(var,1,4, “”)

or

substitute(var,“_bar”,“”)

Thanks,

Ana

Hi Ana,

Both foo and bar are variable, eg., foo (formulation, treament…) and bar (T, R, A…) I want to avoid manual entries which seem to be necessary in filters.

For a custom transformation, in your case you can also use

replace(var,1,4, "")
or
substitute(var,"_bar","")

For the first one I do not know the number 4 beforehand and for the second on what “bar” actually is. :wink: I guess I have to stick to my clumsy formula.

Another suggestion

replace(var, 1, search(var,“_”,1),“”)

Almost there. I don’t know the length of ”bar” (can be >1) – but

replace(var, 1, search(var, '_', length(var)-1), '')

works.

THX!