how do i add zeroes at the beginning of a string so the total length will be 10 digits

  • 2 March 2021
  • 3 replies
  • 63 views

I got a client ID (a number), (Example: 123456)

I got the length of it by using the command "Get Length".

The length will always be less then 10 digits,

But I want it to be equal to 10. (Example: 0000123456)

how can I accomplish that?

 

thanx in advance


3 replies

Hi!

 

You can achieve this by using a loop:

Keep adding a "0" character to the beginning of the string representing your value (using the "set variable" advanced command) until the length is 10 exactly. Please see the below/attached screenshot.

 

 

Hope that answers your question!

 

Kind regards,

Theo

thank u for the idea

is there an option of doing this without the loop?

I don't know why but I'm sure that there is a way without it...

Yes, actually, but I was too tired it seems yesterday to come up with it and a colleague pointed it out this morning (guess I needed more coffee ? 😞

 

Just use two advanced commands:

  1. Add "0000000000" to the beginning of your variable/value
  2. Then just get the last (from the right) 10 characters using the "find" command and a regex "[0-9]{10}$"

 

See the below screenshots and thanks to @Artur Martirosyan​ for the pointer on this!

 

Reply