Hi all,
Spoiler alert - “dumb” question ahead!
How can we add leading zeros to a string?
Give or take something like padStart
Thanks
Hi all,
Spoiler alert - “dumb” question ahead!
How can we add leading zeros to a string?
Give or take something like padStart
Thanks
Not a dumb question; so many people face this issue.
I solved it for one client recently (a different use case but include your solution.)
Watch here: Loom Message - 17 February 2023 | Loom
Pretty simple, add ’ at 0 value and use replace function to pass it as string.
This is a very common problem with zip codes or telephon numbers.
I’d like to add my go-to solution:
convert the input string to a number format
“4567” → 4567
Add 10… to the number
4567 + 10 000 000 = 10 004 567
convert the number back to a string
10 004 567 → “10004567”
remove the first character of the new string
“10004567” → “0004567”
This would be the make formula for a output string with 7 characters,
{{substring(toString(parseNumber( INPUTDATA ; ) + 10000000); 1; 8)}}
you can just copy and paste this into make
you can modify this however you like, for example this is the formula for 10 characters
{{substring(toString(parseNumber( INPUTDATA ; ) + 10000000000); 1; 11)}}
it’s best to filter your input data to avoid errors. You can do this with a MatchPattern filter. for example:
^[0-9]{1,7}$
This pattern will only allow strings which contain numbers between 0 and 9 and have a minimum of 1 character and a maximum of 7 characters.
^[2,4,6,8]{3,11}$
This pattern will only allow strings which contain the numbers 2, 4, 6 or 8 and have a minimum of 3 characters and a maximum of 11 characters.