[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to TRIM zeroes from the left portion of a string

Posted on 2008-11-10
7
Medium Priority
?
415 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:lshane
  • 4
  • 3
7 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22925539
Dim x
x="000123"
x = CInt(x)
0
 

Author Comment

by:lshane
ID: 22926019
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?
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 22926187
That's effectively what CInt() will do. Did you try it? If you are having problems then add zero the result of CInt():

Dim x
x="000123"
x = 0 + CInt(x)

x should now be just 123
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:lshane
ID: 22926900
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?
0
 

Author Comment

by:lshane
ID: 22926976
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" ?

0
 
LVL 82

Expert Comment

by:hielo
ID: 22927055
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
0
 

Author Closing Comment

by:lshane
ID: 31515242
Awesome!  Thanks so much, hielo!  I appreciate it.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question