cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1733
Views
0
Helpful
3
Replies

How to ensure a variable's character length

rychaney
Cisco Employee
Cisco Employee

Hi,

I am using the divide function and I've found that if the remainder starts with a zero the leading zero is dropped. In my script I want to check if the output of $remainder is 6 characters and if not to add a leading zero, any idea of the best way to do this? I was thinking a regex?

Ryan

3 Replies 3

Joe Clarke
Cisco Employee
Cisco Employee

You can use the string length action for this.

string length $remainder

if $_string_result lt 6

set remainder "0$remainder"

end

Great answer, I didn't know you could do that.

What version of EEM is required for the string length command?

EEM 3.0.