Wrox Programmer Forums
|
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
 
Old May 14th, 2006, 02:07 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default replace function

The follwing function works
function FixID(str)
    FixID = trim(replace(str, "'", ""))
end function
but when I add another fixID to repkace spaces like this
function FixID(str)
    FixID = trim(replace(str, "'", ""))
    FixID = trim(replace(str, " ", ""))
end function
only the first one works(replace ') but not the second one.
how should I change it so it replaces both!



 
Old May 14th, 2006, 11:55 PM
Registered User
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that second function is trimming and replacing single quotes in the function argument str THEN it trims and replaces spaces of that versame argument that was passed. you need to do this to an assigned var...not the str on the second replace


Code:
<%
  Function FixID(str)
   FixID = TRIM(REPLACE(str, "'", ""))
   FixID = TRIM(REPLACE(FixID, " ", ""))
  End Function

  Response.Write FixID("four, score, and, seven, years, ago")
%>

 
Old May 15th, 2006, 12:01 AM
Registered User
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ooops...the example was supposed to have quotes...not commas

Function FixID(str)
   FixID = TRIM(REPLACE(str, "'", ""))
   FixID = TRIM(REPLACE(FixID, " ", ""))
  End Function

  Response.Write FixID("four' score' and' seven' years' ago")

 
Old May 15th, 2006, 12:57 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

Another way to skin the same cat:

  Function FixID(str)
    FixID = ""
    on error resume next
    FixID = CStr(str)
    if (len(FixID) > 0) Then
      FixID = Replace(FixID, "'", "", 1, -1, 1)
      FixID = Replace(FixID, " ", "", 1, -1, 1)
    end if
  End Function


Wind is your friend
Matt





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