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

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.
 
G

Guest

Try: CStr(CLng("0000012345"))

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

John H W
 
J

Jeff Boyce

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>
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top