Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing spaces from a dynamic value from the database

Status
Not open for further replies.

summitmedia

Programmer
May 14, 2002
32
0
0
GB
hi guys

I am trying to remove the spaces from a dynamic value that is returned from my database in asp.

when i pass the value in a url to the next page it replaces the space with %20 is their any way to swap them the %20 for _ so that it appears in the url ok

cheers

dean

cheers

dean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if they can't prove i was logged in when it broke, It a software issue and you ain't seen me right!!
 
did you mean

yourValue=Replace(yourValue," ","_")

and then pass it as a URL

-DNG
 
Are these values actual filenames with spaces in them?
 
hi their

i am using a rewrite script for the url which will add the a headline to the url for the page, but i need it strip the spaces out of the headling and make them into "_" so that the url will be able to be used a spider friendly link.

I am just testing the replace option from dotnetgnat and i will let you both know if it works in a minute ok

cheers

dean

cheers

dean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if they can't prove i was logged in when it broke, It a software issue and you ain't seen me right!!
 
hi dotnetgnat

i added what you said like so:

Headline=<%= Replace(CarParkingNews.Fields.Item("Headline").Value," ","_") %>

and i am getting this error:
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: '[string: "CCTV_traffic_system_"]'
/dean/bemrosebooth/ line 380

i have spotted that one of headleines has a "(" and ")" round a bit of text in it.

can i put more that one replace on the same value. so to remove all of these "><()* kind of values that will affect the string working

all your help is most appreaciated

cheers

dean


cheers

dean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if they can't prove i was logged in when it broke, It a software issue and you ain't seen me right!!
 
hi dotnetgnat

i added what you said like so:

Headline=<%= Replace(CarParkingNews.Fields.Item("Headline").Value," ","_") %>

and i am getting this error:
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: '[string: "CCTV_traffic_system_"]'


i have spotted that one of headleines has a "(" and ")" round a bit of text in it.

can i put more that one replace on the same value. so to remove all of these "><()* kind of values that will affect the string working

all your help is most appreaciated

cheers

dean


cheers

dean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if they can't prove i was logged in when it broke, It a software issue and you ain't seen me right!!
 
sorry for the double submit my browser played up a little

cheers

dean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if they can't prove i was logged in when it broke, It a software issue and you ain't seen me right!!
 
can i put more that one replace on the same value

YES.

can you show us a sample value for CarParkingNews.Fields.Item("Headline").Value

-DNG

 
hi dotnetgnat

the headline that produced the error above is:

CCTV traffic system (ParkingEye) to hit Scotland's streets in a 'matter of months'

which is why i want to strip out ()*"? values




cheers

dean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if they can't prove i was logged in when it broke, It a software issue and you ain't seen me right!!
 
hi donnetgnat

i'll try this over the weekend and get back to you monday and let you know how i get

cheers

dean

cheers

dean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if they can't prove i was logged in when it broke, It a software issue and you ain't seen me right!!
 
ok..just post back if you have any problems using the regular expressions...

-DNG
 
it just looks a lot of code, is their easyier way of doing it like the simple replace() option

cheers

dean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if they can't prove i was logged in when it broke, It a software issue and you ain't seen me right!!
 
you will need to use lof of nested Replace() fnctions then and you need to know what characters you want to replace...if some new weird character comes up then you need to code again...but with regular expressions it is pretty straight forward...and it is not lot of code...just try it out...

as far as nested Replaces..something like this...

Replace(Replace(yourString," ","-"),"(","")

-DNG
 
ill try that

catch you on monday

cheers

dean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if they can't prove i was logged in when it broke, It a software issue and you ain't seen me right!!
 
hi DNG

i tried to add the regular expressions but couldn't get my head around it.

so i ended up with a few nested Replace() tags.

could you give me an example of how the regular expression fits into a page, one i set where it fits into a page then i will be able to understand it better.

cheers

dean

cheers

dean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if they can't prove i was logged in when it broke, It a software issue and you ain't seen me right!!
 
here is an example dean,

Tweak and make it work to your needs...

here is the function:
Code:
Function RegExpTest(patrn, strng)
  Dim regEx, retVal
  Set regEx = New RegExp
  regEx.Pattern = patrn
  regEx.IgnoreCase = False
  retVal = regEx.Test(strng)
  RegExpTest = retVal
  Set regEx = Nothing
End Function

this is how we call it:
Code:
If RegExpTest("[^a-zA-Z_0-9]","yourstring") = True Then
'then you have some non alphanumeric characters    
Else
'everything is fine
End If

hope this helps

-DNG
 
in the calling routine..you can change your pattern to whatever you want and remove everything you want...if encountered with some problem, please post back with the code you tried...

-DNG
 
hi DNG

Bit Brain Dead if this is the current config i have using the Replace() where would i put the code above to make it work.

this way i can see the code insitue and it will make sence as i was up till 4 watching bb6,

here is the ocde that would produce 1 hyperlink that needs to have the link stripped of the rubbish

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../../Connections/connection.asp" -->
<%
Dim CarParking__MMColParam
CarParking__MMColParam = "1"
If (Request.QueryString("ArticleID") <> "") Then
CarParking__MMColParam = Request.QueryString("ArticleID")
End If
%>

<%
set CarParking = Server.CreateObject("ADODB.Recordset")
CarParking.ActiveConnection = MM_user_STRING
CarParking.Source = "SELECT * FROM dbo.Car_parking_all_areas WHERE ArticleID = " + Replace(CarParking__MMColParam, "'", "''") + ""
CarParking.CursorType = 3
CarParking.CursorLocation = 3
CarParking.LockType = 1
CarParking.Open()
CarParking_numRows = 0
%>
<html>

<head>
<title> <%=(CarParking.Fields.Item("Headline").Value)%></title>
<a href="../intel.asp?area=car_parking_news_articles&ArticleID=<%= CarParking.Fields.Item("ArticleID").Value %>&Headline=<%= Replace(Replace(Replace(Replace(Replace(Replace(CarParking.Fields.Item("Headline").Value," ","_"),"(",""),")","")," - ",""),".","_"),"-","_") %>">
</head>
<body>
</body>
</html>
<%
CarParking.Close()
%>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

guide me oh master where should the code go.




cheers

dean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
insomia!!! love it!!! who needs sleep that's for normal folk with only 5 fingers.
Programmers bible, wiredus awakeus 24:7
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top