Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 14th, 2010, 02:25 PM
Authorized User
Points: 405, Level: 7
Points: 405, Level: 7 Points: 405, Level: 7 Points: 405, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default LTrim/RTrim

Hi there

I have a 16 digit number in my database that I pull out of the database as a recordset - I need to convert it into 4 blocks of 4 on the page - would I use LTrim and RTrim and if so, how would I go about it?

I'm thinking

'first 4 digits

strNo1 = LTrim(recordset("number", 4))

'second 4 digits

strNo2 = LTrim(recordset("number", 4))

'third4 digits

strNo3 = LTrim(recordset("number", 4))

'fourth 4 digits

strNo4 = RTrim(recordset("number", 4))

I know that strNo2 and strNo3 should pull out the first 4 digits but I don't know how to go about pulling out the second 4 and third 4.

Any help much appreciated.


Reply With Quote
  #2 (permalink)  
Old June 15th, 2010, 10:33 AM
Registered User
Join Date: Jun 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

LTrim and RTrim are not the functoins you'd want to use. Try using the "Mid" function instead

Dim MyNumber
MyNumber = "1234567890123456"
Response.Write( Mid(MyNumber , 5, 8) )

Reply With Quote
  #3 (permalink)  
Old June 15th, 2010, 07:18 PM
Friend of Wrox
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts

Ummm...ClassicASP: That would produce the string "56789012" in the variable MyNumber.

In VBScript, MID's third argument is the *length* of the string, not the ending position as it is in other languages.


If you put the 4 pieces into 4 elements of an array, it's neater code:
Dim chunks(4)
Dim num 
num = CStr( rs("number") )
For i = 1 To 4
    chunks(i) = Left(num,4)
    num = Mid(num,5)
Then your four strings will be named chunks[1] through chunks[4]
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
adamhw (June 16th, 2010)

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 16 Error? - Missing RTrim wrozyboy BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 0 February 18th, 2010 09:12 PM
rtrim, ltrim and len khronikles Pro VB Databases 1 June 5th, 2006 03:31 PM
rtrim or substring? Help bachuss SQL Server 2000 3 March 1st, 2006 01:05 PM
difference in the codwithout ltrim and right trim shoakat Classic ASP Databases 2 October 30th, 2004 01:40 AM

All times are GMT -4. The time now is 05:58 PM.

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