Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic 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 June 25th, 2004, 08:16 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default Removing a non unique char from string

Good Day

Is the a VBS function that will remove a , from the end of a string?
I am aware of left,right and mid functions to get values, what if I want to remove a character?

If this char is unique I can use replace to replace it with an ""
, however it's something like:

strBefore = 10/03,11/03,12/03,14/03,15/03,

What I have done is:
getlength = Len(aString)
strAfter = left(aString, getlength - 1)

There must be a one function move for this surely?

Thank you in advance

Wind is your friend
Matt
__________________
Wind is your friend
Matt
 
Old June 25th, 2004, 08:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

What you do is right Matt.

May be you can put that in one line like this.
Code:
strAfter = left(aString, Len(aString) - 1)
Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 25th, 2004, 08:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

No, there isn't. You'll need to use Left and Len, although you could write it in one statement:

strAfter = Left(aString, Len(aString) - 1)

or

aString = Left(aString, Len(aString) - 1)

to reassign the value of aString back to aStrign immediately.

You could also use InStrRev to get the position of the last comma in the string. Look at the Functions list for VB Script for more details: http://msdn.microsoft.com/library/de...iFunctions.asp

But it all comes down to the same.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 25th, 2004, 08:24 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Matt,

Don't think there is a single function, but IMO regular expressions are a nice way to do it...

Code:
Dim myString: myString = "1,2,3,4,"
Dim myExp: Set myExp = New RegExp
myExp.Pattern = ",$"
Response.Write myExp.Replace(myString, "")
Set myExp = Nothing
Best regards,

Chris

 
Old June 25th, 2004, 08:41 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

What can I say, the quickest replys in history - thanking you all kindly!

Ahh - InstrRev I had forgotten about that one.

Regards


Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
char[...] or string.charAt(...) Ibn_Aziz Java Basics 1 June 14th, 2006 07:08 PM
getting the last CHAR of a string kondapally Crystal Reports 0 December 13th, 2004 03:39 PM
Find the frequency of a char(s) in a string jdang67 SQL Language 8 October 14th, 2004 02:47 AM
Replace or remove the last char from the string sabu21s XSLT 12 January 8th, 2004 05:26 PM





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