//flex table opened by JP

Click to See Complete Forum and Search --> : String parsing


DanielAc
02-02-2002, 08:34 AM
I have two types of values that are going to be pulled from a database. Those values *WITH* 'http://' appended to the start of the URL and those without. Example:
www.favoritesite.com and http://www.favoritesite.com or someone may even enter something like jamminband.mp3.com.

I need some serverside javascript that will check to see that the http:// is stripped from the DB value before the Response.Write.

So we have.

Response.Write "Home Page: <a href='" & Trim(rs("fldHomePage")) & "'>" & Trim(rs("fldHomePage")) & "</a>"

Is there some way to call a function here like:

Dim hpValue
hpValue = Function(Removehttp://fromvalues) Trim(rs("fldHomePage"))

Response.Write "Home Page: <a href='" & hpValue & "'>" & hpValue & "</a>"


Does it make more sense to do this when the data is being entered? If so how? The processing .ASP page does not have html, head, or body tags.

strHomePage = Trim(Request.Querystring("home"))
' Simple VBScript should do it for posting to the DB
' Lets say record column contains http://www.myband.com then..

If InStr(strHomePage, 1, http://) Then
strHomePage = RTRIM(strHomePage, 7)
End If

Something like this to get started?

qball
02-02-2002, 04:44 PM
its 2002 and still parsing....

Anyway, coupla questions:

Don't you need the "http:\\" in the anchor tag href? Let's try:

without:
<a href="www.sysopt.com">sysopt wifout http:\</a>

with:
<a href="http:\\www.sysopt.com">sysopt wifout http:\</a>

well, that didn't exactly work, added the ubb url tag...

Next, why does DB have mixed URLs? Considering a text field holding a URL like string, all should have "http:\\" or all should not have "http:\\". This can be accomplished many ways.

See, now things are easy.

DanielAc
02-02-2002, 04:59 PM
Your right. The database should not have mixed strings.

There should be error checking to begin with.

So now back to the drawing board.

BTW I got this far with the (parsing?)

Function HTTPpolice(strAddress)
strHTTP=Trim(rs("fldHomePage"))
checkHTTP=Replace(Ucase(strHTTP),"HTTP://", "")
If Len(strHTTP)<>Len(checkHTTP) Then
checkHTTP=Right(strHTTP,Len(checkHTTP))
End If
End Function

As pretty as it is, it is really irrelavant since the DB should contain ALL http://www.urls.com , or http://myjam.mp3.com etc.

Something like this on the Data post???

strHomePage = Trim(Request.Querystring("home"))
strHomePage=Replace(Trim(Request.QueryString("home")),"http://","")
strHomePage = "http://" & strHomePage

qball
02-04-2002, 07:55 PM
fix the DB, it is the problem. might not be option...

ok, you can do this in ASP after getting your result set. This is messy to say the least and inefficient as you run this code for every URL. On to psuedo-code

//to add url
if pos(url,':\\') > 4 then
//do nuffin http exists
else
url = 'http:\\' + url
end if

//to remove url
if pos(url,':\\') > 4 then
url = left(url, pos(url,'http:\\'))
else
//do nuffin http not there
end if

Lastly, a better way to remove 'http:\\', dependent upon DBMS, never SELECT 'http:\\' iffin it exists.

SELECT
c1,
c2,
LEFT(url,pos(url,'http:\\')),
c4
FROM
tables
WHERE...

Dependent upon pos DB function retval, you may need:

max(pos(url,'http:\\'), 1)