manipulation: Delete the digits on the left if they are zero

#1

Hello KNIMER,
grafik

As you can See in the picture, I have a column with the name “Serien”, if a number starts with zero I want to delete it automatically. If there are more zeros it shall delete all of them.

Thank you very much for your help :slight_smile:

0 Likes

#2

Hi @Alex1990,

typical Regex topic :wink:
Use the String Manipulation String with

regexReplace($Serien$, “^0+”, “”)

regards, Tommy

3 Likes

#3

Or the String Replacer:

image

But I am wondering: is there any way to do this without using regexes? :thinking: For many beginners regexes are a big scary mystery. I could come up with some crazy complex loop constructs, but there has to be a simpler way… Something like the “stripstart” function in the String Manipulation node, but that one only does whitespace.

Best
Aswin

2 Likes

#4

Thank you @tommy it works!!

@aswin as long as the regex works for me I am happy :smiley:

But I appreciate your help :slight_smile:

2 Likes

#5

To answer my own question, one could do this in a String Manipulation node…

replaceChars(stripStart(replaceChars($Serien$, "0", " ")), " ", "0")

not very elegant though, and only works if you don’t have whitespace…

Edit: maybe using a tab instead of a space in the expression above would work better, since tabs are less likely to occur in normal strings.

2 Likes

#6

Hi Aswin, I also hear a common transformation problem.
Using (several) loops wouldn’t be smarter.
As this issue should be in the TOP10 of the Regex world and the pattern is quite simple, I think providing the Regex-solution doesn’t overwhelm sb.
However, you’re right, a function like “stripstart” would be great with an option to delete the first char or the first n chars.

regards, Tommy

1 Like

#7

Hi all,

you can find this function in the

column expression

node.

Cheers, Iris

0 Likes

#8

Actually, the String Manipulation node has also the Strip Function. :slight_smile:

1 Like

#9

But can you make those strip functions strip anything else than whitespace? :slightly_smiling_face:

1 Like

#10

Hi,

I think it is meant only for whitespace.

@Iris: correct me if i am wrong.

Regards,
Pavan.

1 Like

#11

Hi there all,

@pawanmtm correct, only for whitespaces.

@Aswin Java and JavaScript (String Manipulation and Column Expressions node) native strip/trim functions do not receive any argument and only can remove white spaces. I guess enhancement of this functions would mean to use regex :slight_smile: Python strip function for example accepts argument and can do what you are looking for.

@Alex1990 seems to me that you can use String To Number node to remove zeroes :wink:

Br,
Ivan

2 Likes

#12

But in @Alex1990’s example the “Serien” column also contains letters sometimes…

1 Like

#13

You are right. Didn’t see that X although it is first char in first row :smiley:

Br,
Ivan

1 Like