Jump to content
Sign in to follow this  
lavascript

Expand strings to a predetermined length?

Recommended Posts

lavascript

I need to expand a string to a predetermined length using a fill character. In this case, I'm reading a CSV file, and I need to take the employee number, which can be anywhere between 3 and 6 characters, and expand it to eight using leading zeros.

My current method uses a Switch statement, but I was wondering if there was a UDF I had overlooked, or a more elegant or clever way to go about it than:

Switch StringLen($empNum[$i])
Case 2
   $hralias="HR000000"&$empNum[$i]
Case 3
   $hralias="HR00000"&$empNum[$i]
Case 4
   $hralias="HR0000"&$empNum[$i]
Case 5
   $hralias="HR000"&$empNum[$i]
Case 6
   $hralias="HR00"&$empNum[$i]
Case 7
   $hralias="HR0"&$empNum[$i]
Case 8
   $hralias="HR"&$empNum[$i]
EndSwitch

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×