Yep you're super right and I felt into that kind of issue. I solved it by using zerofill numbers.
I think I used r0j0's way too once. Don't remember, I tend to reinvent the wheel sometimes :D
with zerofill you don't fall into the substring issue
if you replace(str,"001","") you won't have any issue
and you can still int("003") into 3 with no problem.
But yeah... use r0j0's way... it's the cleanest (: