jasonsalas
IS-IT--Management
Hi everyone,
I'm trying to develop an ASP script for a news site that will look at a
body
of text (inputted from a <TEXTAREA> form field), and evaluate the text and
assign HTML <a href>...</a> formatting if the body of text contains a
certain string (like famous people's names, companies, etc.), linking to
their sites. The script will need to do this only to the first instance of
the text found within the string. This is easy enough, using VBScript's
RegExp object.
But, here's the catch: I've got about 30 such known strings.
I'm thinking of using a dictionary or array to store the values, but I'm
stuck on how to code this...and if this is even the best avenue to pursue.
I'm also pondering using XML to hold the link values. Can RegExp hold
multiple values? Or can it call upon an array?
Following is what I have as a demo for single values.
Any suggestions?
***************************************************************************
*
**
formatstory.asp
***************************************************************************
*
**
<% @ Language = VBScript %>
<% Option Explicit %>
<%
Dim objRegExp, strName, searchString, strName2
Set objRegExp = New RegExp ' instantiate a Regular Expression object
strName = "Michael Randolh Johnson is the Governor of Palookaville.
Michael
Randolh Johnson is married to Mrs. Johnson, and Michael Randolh Johnson is
corrupt as sin. Michael Randolh Johnson's Web site is
searchString = "Michael Randolh Johnson "
' set the pattern...allow all letters, apostrophes, and hyphens
objRegExp.Pattern = "\b" & searchString & "\b"
' ignore case
objRegExp.IgnoreCase = True
objRegExp.Global = False ' apply changes to only the first instance of the
phrase
' see if the Regular Expression is found within the string
Response.Write "<b>Before applying the Replace function</b><br>" & strName
Response.Write "<p><b>After applying the Replace function</b><br>"
' apply the replace method
strName = objRegExp.Replace(strName," <a
href="" Randolh Johnson</a>
"
Response.Write strName
Set objRegExp = Nothing
%>
I'm trying to develop an ASP script for a news site that will look at a
body
of text (inputted from a <TEXTAREA> form field), and evaluate the text and
assign HTML <a href>...</a> formatting if the body of text contains a
certain string (like famous people's names, companies, etc.), linking to
their sites. The script will need to do this only to the first instance of
the text found within the string. This is easy enough, using VBScript's
RegExp object.
But, here's the catch: I've got about 30 such known strings.
I'm thinking of using a dictionary or array to store the values, but I'm
stuck on how to code this...and if this is even the best avenue to pursue.
I'm also pondering using XML to hold the link values. Can RegExp hold
multiple values? Or can it call upon an array?
Following is what I have as a demo for single values.
Any suggestions?
***************************************************************************
*
**
formatstory.asp
***************************************************************************
*
**
<% @ Language = VBScript %>
<% Option Explicit %>
<%
Dim objRegExp, strName, searchString, strName2
Set objRegExp = New RegExp ' instantiate a Regular Expression object
strName = "Michael Randolh Johnson is the Governor of Palookaville.
Michael
Randolh Johnson is married to Mrs. Johnson, and Michael Randolh Johnson is
corrupt as sin. Michael Randolh Johnson's Web site is
searchString = "Michael Randolh Johnson "
' set the pattern...allow all letters, apostrophes, and hyphens
objRegExp.Pattern = "\b" & searchString & "\b"
' ignore case
objRegExp.IgnoreCase = True
objRegExp.Global = False ' apply changes to only the first instance of the
phrase
' see if the Regular Expression is found within the string
Response.Write "<b>Before applying the Replace function</b><br>" & strName
Response.Write "<p><b>After applying the Replace function</b><br>"
' apply the replace method
strName = objRegExp.Replace(strName," <a
href="" Randolh Johnson</a>
"
Response.Write strName
Set objRegExp = Nothing
%>