Hello KNIMER,
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
Hello KNIMER,
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
Hi @Alex1990,
typical Regex topic
Use the String Manipulation String with
regexReplace($Serien$, “^0+”, “”)
regards, Tommy
Or the String Replacer:
But I am wondering: is there any way to do this without using regexes? 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
Thank you @tommy it works!!
@aswin as long as the regex works for me I am happy
But I appreciate your help
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.
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
Actually, the String Manipulation node has also the Strip Function.
But can you make those strip functions strip anything else than whitespace?
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 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
Br,
Ivan
But in @Alex1990’s example the “Serien” column also contains letters sometimes…
You are right. Didn’t see that X although it is first char in first row
Br,
Ivan
I would do something like
join((replace(substr($Serien$,0 ,1 ),“0” ,"" )),substr($Serien$,1))
I normally prefer to create new column for each string manipulation to have more control on the final outcome and then collect in a more complex string manipulation
Cool alternative! But it looks like that this method works with “0987” but not with “0098”. @Alex1990 wrote “If there are more zeros it shall delete all of them”. Can it be changed to replace multiple 0s? One could put it in a recursive loop and run it multiple times
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.