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 August 18th, 2005, 03:53 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 Help with replace function

This seems so simple - I thought my understanding of the replace function was fairly good until today. Here is my problem simplified:

1..I have a string "3454.5". I would like to replace the last digit with an empty space,why can I not use the replace function like so: (for various reasons I would like to reach my solution the way I have tryed?)

dim myString,tweaked
myString = "3454.5"
tweaked = replace(myString,"5","",(len(myString)-1),1)
response.write tweaked

My objective is to get the string 3454.

Someone please correct me, My understanding of the replace function:

Replace(expression, find, replacewith[, start[, count[, compare]]])

Why is my start location ignoring my len(myString)-1)? Even if I hard code a number in there it still bahaves badly.


Wind is your friend
Wind is your friend
Old August 18th, 2005, 04:33 AM
Friend of Wrox
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post

Hi Matt,

When using the start parameter, Replace() just returns the string from that point onwards - it's probably returning '.' at the moment.

To get what you want, you need something like:
tweaked = Left(myString, Len(myString) - 2) & Replace(myString, "5", "", Len(myString) - 1)


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extending the Replace Function designdawg Access 9 February 19th, 2008 12:39 PM
Replace Function Query rsm42 ASP.NET 1.0 and 1.1 Basics 4 August 4th, 2007 05:29 AM
replace function keyvanjan Classic ASP Basics 3 May 15th, 2006 12:57 AM
Character replace function? echovue Access 2 December 21st, 2004 01:53 PM
replace function Adam H-W Classic ASP Basics 3 September 20th, 2004 09:09 PM

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