DjDeep00 Posted July 31, 2007 Share Posted July 31, 2007 The result I get from the following code is "Test_2" but I am trying to get "Test_0002". Sorry in advance, for this silly question.... $Number='Test_0001' $Number_Split=StringSplit($Number,"_") $Next_Number=$Number_Split[1] & "_" & $Number_Split[2]+1 MsgBox(4096,"",$Next_Number) Link to comment Share on other sites More sharing options...
bluebearr Posted July 31, 2007 Share Posted July 31, 2007 When you add 1 to the string '001', AutoIt converts the string ('001') to a number to perform the addition. Numbers don't have leading zeros, and so they don't show up in the result. Use something like this: $Number='Test_0001' $Number_Split=StringSplit($Number,"_") $Next_Number=$Number_Split[1] & "_" & _Pad($Number_Split[2]+1, 3) MsgBox(4096,"",$Next_Number) Func _Pad($num, $len) Local $zeros = '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' Return StringLeft($zeros, $len - Stringlen($num)) & $num EndFunc BlueBearrOddly enough, this is what I do for fun. Link to comment Share on other sites More sharing options...
weaponx Posted July 31, 2007 Share Posted July 31, 2007 (edited) StringFormat has built-in precision flags for leading and trailing digits $Number='Test_0001' $Number_Split=StringSplit($Number,"_") ;%04d pads to 4 places, %03d would pad to 3 $Next_Number=$Number_Split[1] & "_" & StringFormat("%04d", $Number_Split[2] + 1) MsgBox(4096,"",$Next_Number) Edited July 31, 2007 by weaponx Link to comment Share on other sites More sharing options...
DjDeep00 Posted July 31, 2007 Author Share Posted July 31, 2007 Beautiful...Thanx guys. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now