Remove "@en" characters at end of variable length strings.

I have been trying to remove the characters “@en” from the end of variable length strings. I’ve tried the following substr($TERM$,0 ,indexOfChars($TERM$, “@en”) ) inside the string manipulation node. However, the results are not as expected. For example if the term is “temporal region@en”, I want to get back just “temporal region”, instead I am receiving just “t”. It also doesn’t work with just @ or just en, since it is stripping these characters out from everywhere in the string. I know the solution is probably simple, but I can’t figure out how to do this. Can anyone help? The @en is always found at the end of the strings, but string lengths are variable.

Hi @jayshan , that is because you are using indexOfChars() instead of indexOf().

indexOfChars() will look for any of the characters (chars) you send, so it will look for either of “@” or “e” or “n”, and since “temporal” has an “e” after the “t”, the indexOfChars() got the index of “e”, and therefore returns you everything up to before the “e”, which is effectively “t”.

What you want is indexOf() instead:
substr($TERM$,0 ,indexOf($TERM$, "@en") )

However, this approach will look for the first instance of “@en” wherever it is. So if you have a string as “temporal @en region”, you will get "temporal " only. Unless you are guaranteed that the “@en” is always at the end.

Another thing is that, with this approach, if there is no “@en”, you will not get anything returned for the indexOf(), therefore your substr() will return nothing.

And also, if it’s always “@en” and it’s always at the end, you might as well do:
substr($TERM$, 0, length($TERM$) - 3)

which will be faster than doing indexOf(). Getting the length of a string is much faster than having to search for a substring within a string.

There are a few ways to apply only if “@en” is at the end. Just let us know if you need this or not (that is if it is not guaranteed that “@en” will always be at the end)


alternatively you might want to try a regex replace “@en$” with “”


Thank you so much for breaking this down for me. I didn’t realize the differences or constraints of using that indexOf… Your explanation was a big help.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.