Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. 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 Professional 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 September 29th, 2003, 06:59 AM
Authorized User
 
Join Date: Jul 2003
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I get rid of the last character in a string

Hi there

Please could someone help me with the following:
I am producing results on a page (taken from my database) and separating each item with a comma. The following code is within a loop so that I keep getting results out until the end of the records.

response.write rs_recordsetALL.Fields.Item("Item_No").Value & ", "

This gives me something like:
8EP333, 8EP564, 8EP716,

I would like to remove the last comma from the string (string can be any length, depending on the results found) so that it reads:
8EP333, 8EP564, 8EP716

Can anyone help out?

Thanks in advance

Lucy

 
Old September 29th, 2003, 07:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Either
1. use Left(theString, Len(theString) - 1) to remove the comma at the end (although you cannot do this once it has been written to the response object, so you'll have to write the whole thing to a temporary string, then strip the trailing comma, then use Response.Write)
or
2. Write your loop slightly different so you don't end up with a trailing comma, e.g.
Code:
' write the first value outside the loop, without a comma
Response.Write rs_recordsetALL.Fields.Item("Item_No").Value
rs_recordsetALL.MoveNext
Do While Not rs_recordsetALL.EOF
    Response.Write ", " 
    Response.Write rs_recordsetALL.Fields.Item("Item_No").Value
    rs_recordsetALL.MoveNext
Loop
 
Old September 29th, 2003, 07:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

There's a 3rd alternative, if "Item_No" is the only field in your recordset then you can use the join function to do it for you without any loop:
Code:
Response.Write Join(rs_recordsetALL.GetRows(), ",")
 
Old September 30th, 2003, 05:33 AM
Authorized User
 
Join Date: Jul 2003
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help - point 2 worked a treat!!

Lucy






Similar Threads
Thread Thread Starter Forum Replies Last Post
string character conversion Neal XSLT 2 February 23rd, 2006 08:23 AM
Delete last a character in string dtho Excel VBA 27 December 7th, 2005 01:01 PM
Cutting a character from a string arnabghosh Classic ASP Basics 2 August 18th, 2005 07:44 AM
Replacing a character from string itHighway Classic ASP Basics 5 March 14th, 2005 11:15 PM
Search for Character in String Kaynor09 Excel VBA 2 April 24th, 2004 11:13 AM





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