Remove n number of characters from the end of the strings in a column

I read someone had difficulties with this function.
Now I am trying to figure out the same thing and I have a suggestion on that:
We currently have String Manipulation (node) > removeChars(str, chars) (function), and some combo of length and substring.
I think it would be great to have removeNChars added as follows:

  1. removeNChars(str, n)
    or for better interpretation
  2. removeNChars(str, start/end, n)
    where str is the string to manipulate and
    n is the number of symbols to remove (trim).
    In 1. n>0 would mean “remove n chars from start”; n<0 would mean “remove n chars from end”
    in 2. n could follow the current logic (<0 defaults to 0) and start/end would mark from which position the counter should start counting.

I’d appreciate thoughts on this.

1 Like

Hi,

In the Column expressions node in the latest version was added the function right() (and also left()) and they behave like in excel … extracts the rightmost (leftmost) characters of a string.

1 Like

Sorry, but I can’t find such a node, nor these functions in the String Manipulation node. My version is 4.2.3.

Hi,

The node is part of the KNIME labs group

Maybe you have not installed it … look at Community extensions … https://www.knime.com/community

1 Like

Just to make it clear and to avoid future reader’s confusion, I found what you talk about here:
image
and somehow it does install in the group: KNIME Labs in the Node Repository
All clear, thanks!

But… oh, gosh, if I have to go through this node!
My suggestion still holds.

Hello @deicide_bg,

don’t think there is a need for such function as substring() function seems pretty straightforward:

  • substr($col_name$, n) :arrow_right: removes first n chars from string
  • substr($col_name$, 0, length($col_name$) - n ) :arrow_right: removes last n chars from string

Hope this helps!

Br,
Ivan

5 Likes

You may be right. I went down a bit different path of thought, the one that goes to a left/right (excel-like) function. Thanks for the response!

1 Like

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