How to remove the last three characters from a string with a dynamic length in Azure Data Factory?

Viewed 4983

I have a string variable in Azure Data Factory (v2) from which I want to remove the last 3 characters. Initially I thought using the substring operation, it requires startIndex and length parameters. However the startIndex can vary because the string does not have a fixed length. Any suggestions on how to tackle this?

Example, remove last 3 characters, string length varies:

'abcdef' -> 'abc'
'helloworld' -> 'hellowo'
'2020_18' -> '2020'
1 Answers
  1. We can use length function to get the length of the string.

  2. Then we can use substring function, the expression like substring('String',0, length-3).

  3. In ADF, we can use the expression @substring('helloworld',0,sub(length('helloworld'),3)) to remove the last 3 characters

Related