← All ideas
  • Published 9 Jun 2022

Slice string with negative position should take the ending characters

As an example, if you have the string "12345" and you use a slice string node on it with a position of 2, the resulting string will be "345".

Now, if you set the position to -2, the result is exactly the same as if the position was 0: "12345".

My suggestion is for negative position values to remove characters from the end of the string, so a position of -2 would result in "123".

This is similar to how Javascript's string.slice() works and it is particularly useful for situations where you want to left pad a string.

For example, you want to have a two digit number which changes over time, but when its value is a single digit then it should start with a zero. Like so:

01 02 ... 09 10 11

One way one could accomplish this is by concatenating a zero to the start of a string and then slicing it with a position of -2. It would look something like this:

01 -> slice(-2) = 01

010 -> slice(-2) = 10

As the slice currently stands negative positions are completely unused and useless, but making them mean something would more than double the value of the node.

60%

Development Status: Open

Upvote 3 Downvote 2
mojo
9 Jun 2022

1 Comment

modormoder

slise(len(string)-1)