SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    Minnesota
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP Replace function question.

    I have the variable product_name.
    I am trying to replace any spaces with +, and at the same time remove any commas, colons, semi-colons, hyphens from the variable.

    Is this what I need to do? I'm just guessing here, but does this work? Is there a better way to approach this?
    Thanks

    Replace(Replace(Replace(Trim("product_name")), " ", "+"), ",", ""), ":", "")

    Thanks
    Keomed.com Webmaster
    www.keomed.com

  2. #2
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you tring to get it ready to pass in the URL (querystring)?

  3. #3
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    Minnesota
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, it's actually for the tracking software I use. I customized the traking code to display product names, but then ran into some errors because it doesn't like spaces and other characters.
    Keomed.com Webmaster
    www.keomed.com

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:
    Code:
    server.URLEncode(product_name)

  5. #5
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    Minnesota
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's it? What does that exactly do?


    Thanks!!
    Keomed.com Webmaster
    www.keomed.com

  6. #6
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It just makes the string vaild to pass thru a URL (querystring). You could also try:
    Code:
    server.HTMLEncode(product_name)
    This will change it to HTML code for the stuff like commas, colons, semi-colons, hyphens.

  7. #7
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    Minnesota
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmmm...it doesn't seem to be working.

    Here is the code so it may be easier to troubleshoot
    Code:
    Set rsProduct = Server.CreateObject("ADODB.Recordset")
        rsProduct.Open cmdTemp, , adOpenForwardOnly, adLockReadOnly
    	
    	if rsProduct.EOF then
            product_exists = false
            items_exist = false
        else
            rem this gets item skus for the parent product
            product_exists = true
            product_name = rsProduct("name").value
            product_desc = rsProduct("description")
    
    		sqlText = MSCSQueryMap.keo_items_by_product.SQLCommand
            sqlText = Replace(sqlText, ":1", ProductNum)
            cmdTemp.CommandText = sqlText
            Set rsItems = Server.CreateObject("ADODB.Recordset")
           
            rsItems.Open cmdTemp, , adOpenForwardOnly, adLockReadOnly
    
    		if rsItems.EOF then
    			items_exist = false
    		else 
    			items_exist = true
    		
    		end if
    	end if
    
    %>
    <html>
    <head>
    </head>
    <body>
    <!-- Begin Tracker -->
    	<script language="javascript">
    	var _pn="PROD+<%=Product_name %>"; 	//page name(s)
    	var _mlc="Online+Store";	//multi-level content category
    	var _cp="null"; 		//campaign
    ..........
    As you can see, I added the <%=Product_name"> in the tracker script. The problem is, it doesn't like the quotes, commas, etc.

    Maybe I didn't put your script in the right place. Where would I put it?
    Thanks again
    Keomed.com Webmaster
    www.keomed.com

  8. #8
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this
    Code:
    <script language="javascript">
    	var _pn='PROD+<%=server.HTMLEncode(Product_name)%>'; 	//page name(s)
    	var _mlc="Online+Store";	//multi-level content category
    	var _cp="null"; 		//campaign

  9. #9
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    Minnesota
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I think we're getting there

    Using the URLEncode, Product names such as:
    "Jammal" Giragge Reflex Hammer

    is converted to:

    PROD+%22Jamaal%22+Giraffe+Reflex+Hammer

    Now, how can I get rid of the % symbols??

    Thanks
    Keomed.com Webmaster
    www.keomed.com

  10. #10
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    Minnesota
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, got it to work!

    I combined your idea with codes in my first script:
    Code:
    TrackProdname = Replace(server.URLEncode(product_name), "%", "X")
    Since % was the only special character that seemd to be coming up from the URLEncode, I just replaced that with a "X".

    Cool, thanks DHTMLgod
    Keomed.com Webmaster
    www.keomed.com

  11. #11
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhmm... ok... I'm about to go to bed, but tomorrow, I want to know a few things..

    But no problem, thats what I'm here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •