Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 31st, 2003, 12:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default Padding Zeros

How can I pad zeros to a string of numbers?

I have a user entering a SSN. If a user's SSN begins with a zero, the variable I store it in is droping the zero entered. I was thinking of checking the length of the variable and if it is not = 9 then I will pad it with zeros. What is the code for padding zeros. I do not have my reference books with me here so I was hoping someone can help me on this.

Thanks,
Judy
 
Old July 31st, 2003, 12:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Right("000000000" & strSSN ,9)

The variable strSSN would contain your SSN. Just make sure it is stored as text in the variable and not a number as numbers with drop leading zeros

Chris
 
Old July 31st, 2003, 01:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default

It worked. Thanks for the help.

Judy
 
Old October 13th, 2005, 12:22 PM
Registered User
 
Join Date: Oct 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In Oracle 9i, I found this statement worked

LPAD(strSSN, 9, '0')

it left pads the string with zeros to ensure the length is 9.
 
Old October 9th, 2007, 01:31 AM
Authorized User
 
Join Date: Oct 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the function I prefer:

Code:
Function PadZero(strIn, lngPad)
    If Len(strIn) < lngPad Then strIn = Right(String(lngPad+1,"0") & strIn, lngPad)
    PadZero = strIn
End Function
To use:

Code:
Response.Write(PadZero(1,3))
 
Old January 28th, 2008, 07:38 PM
Registered User
 
Join Date: Jan 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to orizg Send a message via MSN to orizg Send a message via Yahoo to orizg
Default

A solution for VB.NET:

Dim MyNumber As Integer = 472

TxtFormattedNumber.Text = MyNumber.ToString().PadLeft(5, "0")


FYI, you should take a look to String object's PadLeft and PadRight methods.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing leading zeros from a string value vikkiefd XSLT 2 June 12th, 2008 03:30 AM
help with finding zeros of ! ludasky Visual Basic 2005 Basics 1 May 1st, 2008 04:08 PM
Remove Leading and Trailing Zeros lene_wee SQL Server 2000 3 April 1st, 2008 08:23 AM
Suppress zeros from displaying smatyk SQL Server 2000 8 October 27th, 2006 08:12 AM
Zeros at left... comicghozt Access 7 October 3rd, 2006 02:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.