Jump to content
Sign in to follow this  
jvanegmond

Replace All Zero's On Left Hand Side

Recommended Posts

jvanegmond

I'm looking to replace all zero's on the left hand side

Example:

Input: 000018FE

Output: 18FE

Input: 000108F0

Output: 108F0

I've looked at StringRegExp but my mind overloaded so i'm looking for a bit of assistance

Edited by Manadar

Share this post


Link to post
Share on other sites
SmOke_N

Here you go...

MsgBox(0, '', _RemoveDigit("018FE", 0))
Func _RemoveDigit($v_String, $i_Digit)
    If StringInStr($v_String, String($i_Digit)) Then
        For $i_count = 1 To StringLen($v_String)
            If StringMid($v_String, $i_count, 1) <> $i_Digit Then Return StringTrimLeft($v_String, $i_count - 1)
        Next
    EndIf
    Return $v_String
EndFunc

Edit:

Damn I'm slow today!

Edit2:

Had to modify mine, so it counted the number as a string.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
CyberSlug

Larry's should work, but here's an alternative.

$input = "000018FE"
$output = StringFormat ("%X", Dec($input))

MsgBox(0, "Result", $output)

;Similar to Larry's

Func _shorterFunction($input)
    Local $i
    For $i = 1 to StringLen($input)
        If StringMid($input, $i, 1) = "0" Then ContinueLoop
        Return StringMid($input, $i)
    Next
EndFunc

Edit: made $i Local for correctness...

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

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  

×