Link to home
Start Free TrialLog in
Avatar of lshane
lshane

asked on

How to TRIM zeroes from the left portion of a string

Classic ASP VBScript
DWMX/CS3
WIN XP Pro

Hello.

I have a login page for our team where a user enters their employee number.  Sometimes, however, they enter their "full" employee number, which just contains 3 leading zeroes ("000.....") before their number.

This, of course, causes problems when logging in because the entered datat does not contain the leading zeroes.

I would like for any zeroes to the left of a number to be ignored, or removed, from the login after the user presses "submit".  I was looking at TRIM, LTRIM, RTRIM, but they appear to just remove spaces.

How could I accomplish removing/ignoring zeroes?

Example emp number:  203456
Example login (Sometimes): 000203456

Basically, I would like any number of zeroes (Whether 2 or 5, etc.) to be removed/ignored from the left side until it reaches any number other than zero.


Thanks so much,
Shane
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Dim x
x="000123"
x = CInt(x)
Avatar of lshane
lshane

ASKER

Thanks, hielo, for your reply.  That's kind of what I need.  More specifically, though, I need to remove any number of zeroes in the front before a "different" number appears.

Sometimes a user could enter "00123456"...
Other times they could enter "000123456"...
Or even "0123456"...

I just want to be able to have it ignore/remove any zero (however many) in the beginning of the string UNTIL it hits the first "different" number (1, 2, 3, 4, etc.).

Is that possible?
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lshane

ASKER

Hello, hielo.

OK - yes, it did work - to a certain degree.

However... if I type "000123456" or even "123456" then I get the following error:
********************************************************
Error Type:
Microsoft VBScript runtime (0x800A0006)
Overflow: 'CInt'
/testpmcct2/testloginresults.asp, line 5


Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)

Page:
POST 42 bytes to /testpmcct2/testloginresults.asp

POST Data:
username=123456&password=test&Submit=Login
****************************************************************

It's almost like it gives the error if I type MORE than 5 numbers other than zero.
True:  It does remove any zeroes from the beginning, however, it only accepts a 5-digit number after that.

How can that be extended?
Avatar of lshane

ASKER

Hi, hielo.

I discovered if I remove the "C" from the "Cint", that it is able to extend the numbers.

So, what is the significance of the "C" in "Cint" ?

http://www.w3schools.com/VBScript/vbscript_ref_functions.asp
CInt: Converts an expression to a variant of subtype Integer
Int:        Returns the integer part of a specified number


CLng would have also given you a bigger range
Avatar of lshane

ASKER

Awesome!  Thanks so much, hielo!  I appreciate it.