Wrox Programmer Forums
| 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 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
  #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.

thanks

Adam
  #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
Default

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



ClassicASP.com
  #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
Default

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:
Code:
Dim chunks(4)
Dim num 
num = CStr( rs("number") )
For i = 1 To 4
    chunks(i) = Left(num,4)
    num = Mid(num,5)
Next
Then your four strings will be named chunks[1] through chunks[4]
The Following User Says Thank You to Old Pedant For This Useful Post:
adamhw (June 16th, 2010)


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





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