Forums
This topic is locked
trimming by words part II
Posted 27 May 2005 17:09:36
1
has voted
27 May 2005 17:09:36 adam partridge posted:
had to start a new post as existing thread was screwing the psot reply box... anyhowgot a problem im trying to apply the function to some text from a dbase field i know the text has content as i can print it to the screen.. however when i apply the function all i get is the word "and" ( without quotes any ideas :
<pre id=code><font face=courier size=2 id=code><%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/encams.asp" -->
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request("MM_EmptyValue" <> "" Then
Recordset1__MMColParam = Request("MM_EmptyValue"
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset"
Recordset1.ActiveConnection = MM_encams_STRING
Recordset1.Source = "SELECT * FROM dbo.tblpages WHERE intid = " + Replace(Recordset1__MMColParam, "'", "''" + ""
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Function getmiddle(strIn, intLeft, intRight, strWord)
'assign the intCheckIn variable the value of where in the strIn variable the first instance of the word can be found
intCheckIn = InStr(1, strIn, strWord, 1)
'check to see if there are enough available characters for the left-hand side
If intCheckIn < intLeft Then
intCheckOut = 1
Else
intCheckOut = intCheckIn - intLeft
End If
'create output string
getmiddle = Mid(strIn, intCheckOut, intLeft + intRight + Len(strWord))
End Function
%>
<%
intLeft = 150
intRight = 150
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<%=getmiddle("and", intLeft, intRight, Recordset1.Fields.Item("strpagecontent".Value)%>
<br>
<br>
<br>
<%=(Recordset1.Fields.Item("strpagecontent".Value)%>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%> </font id=code></pre id=code>
Replies
Replied 28 May 2005 17:04:29
28 May 2005 17:04:29 adam partridge replied:
finally figured it out if anyone ever needs to do this its : <pre id=code><font face=courier size=2 id=code><%
str ="Litter can be as small as a sweet wrapper, as large as a bag of rubbish, or it can mean lots of items scattered about. keep spain tidy describes litter as waste in the wrong place caused by human agency. In other words, it is only people that make litter. The offence of ‘Leaving Litter’ (section 87 of the Environmental Protection Act 1990; Article 3 of the Litter (NI) Order 1994) says that if a person drops, throws, dePosits or leaves anything so as to cause defacement in a public place, they could be committing a littering offence. About £342 million a year is spent by local authorities in England on street cleaning and litter clearance, with the most common types of litter being cigarette EndPoss, followed by sweet wrappers and matchsticks. An estimated 122 tonnes of cigarette stubs, matchsticks and cigarette related litter is dropped every day across the UK. In a Local Environmental Quality Survey carried out by keep spain tidy in 2002, cigarette related litter was found in 77% of all locations surveyed and confectionery related litter such as sweet wrappers was found in 53% of locations. Drinks related litter such as cans and bottles were found in 31% of all locationsaa."
keyword = "locationsaa"
PadLeft = 100
PadRight = 100
%>
<%
function getmiddle(keyword, str, PadLeft, PadRight)
str = Lcase(str)
keyword = Lcase(keyword)
Pos = InStr(str, keyword)
If Pos > PadLeft Then
StartPos = Pos - PadLeft
Else
StartPos = 1
End If
strlength = PadLeft + len(keyword) + PadRight
getmiddle = Mid(str, StartPos, strlength)
End Function
%>
<%= function getmiddle(keyword, str, PadLeft, PadRight)%> </font id=code></pre id=code>
str ="Litter can be as small as a sweet wrapper, as large as a bag of rubbish, or it can mean lots of items scattered about. keep spain tidy describes litter as waste in the wrong place caused by human agency. In other words, it is only people that make litter. The offence of ‘Leaving Litter’ (section 87 of the Environmental Protection Act 1990; Article 3 of the Litter (NI) Order 1994) says that if a person drops, throws, dePosits or leaves anything so as to cause defacement in a public place, they could be committing a littering offence. About £342 million a year is spent by local authorities in England on street cleaning and litter clearance, with the most common types of litter being cigarette EndPoss, followed by sweet wrappers and matchsticks. An estimated 122 tonnes of cigarette stubs, matchsticks and cigarette related litter is dropped every day across the UK. In a Local Environmental Quality Survey carried out by keep spain tidy in 2002, cigarette related litter was found in 77% of all locations surveyed and confectionery related litter such as sweet wrappers was found in 53% of locations. Drinks related litter such as cans and bottles were found in 31% of all locationsaa."
keyword = "locationsaa"
PadLeft = 100
PadRight = 100
%>
<%
function getmiddle(keyword, str, PadLeft, PadRight)
str = Lcase(str)
keyword = Lcase(keyword)
Pos = InStr(str, keyword)
If Pos > PadLeft Then
StartPos = Pos - PadLeft
Else
StartPos = 1
End If
strlength = PadLeft + len(keyword) + PadRight
getmiddle = Mid(str, StartPos, strlength)
End Function
%>
<%= function getmiddle(keyword, str, PadLeft, PadRight)%> </font id=code></pre id=code>
Replied 28 May 2005 17:20:59
28 May 2005 17:20:59 adam partridge replied:
my next question is how would i highlight the keyword i.e wrap it in <b></b>
Replied 31 May 2005 11:24:15
31 May 2005 11:24:15 Lee Diggins replied:
Like this mebbe?
strlength = PadLeft + len(keyword) + PadRight
str = Replace(str, keyword, "<b>" & keyword & "</b>"
getmiddle = Mid(str, StartPos, strlength)
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
strlength = PadLeft + len(keyword) + PadRight
str = Replace(str, keyword, "<b>" & keyword & "</b>"
getmiddle = Mid(str, StartPos, strlength)
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>