Sign in to follow this  
Followers 0
sshrum

How do I...do zero padding on a value

4 posts in this topic

I am writing a file renaming app and need a way to zero pad a number. I'd like to be able to pass a pad value and a number and have it return back the result; something like:

_zeropad(4,1) -> 0001

_zeropad(4,100) -> 0100

_zeropad(4,10000) -> 10000

Anyone have something handy?

TIA


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

see StringFormat().

msgbox(4096,"",stringformat("%04d",1))
msgbox(4096,"",stringformat("%04d",100))
msgbox(4096,"",stringformat("%04d",1000))

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

NvrMnd....this is what I just whipped up:

Func _ZeroPad($a, $b)
    $c = $a - StringLen($b)
    if $c > 0 Then
        for $d = $c to $a
            $b = "0" & $b
        Next
    EndIf
    return $b
EndFunc

Where $a is the pad and $b is the number to pad. Returns back the padded value.


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

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  
Followers 0