How do I remove leading or trailing zeros from text such as 00012

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to remove leading and trailing zeros (0) from a text string. As
example, I would like the text 0000012345 to be reduced to just 12345. I
have tried the trim, LTrim and RTrim function, but this appears that they
only remove blank spaces.
 
Try: CStr(CLng("0000012345"))

This will convert your string number to a long, then convert it back to a
string.

John H W
 
One approach would be to convert it to a number using, for example, CLng().
Can you guarantee that you will ONLY have digits in the string?

As for removing trailing zeros, since those ARE significant in numbers, you
might have to build a procedure that steps through the string, character by
character, only preserving non-zero characters.

Good luck

Jeff Boyce
<Access MVP>
 
If you're wanting to remove trailnig zeroes, you could also check to see if
the number divides by 10 without a remainder, if it does... divide by 10.
Repeat until there is a remainder.

I don't know if you can do this in Access, this is just my programming
background coming through for a different approach.
 
Back
Top