?
Solved

a dynamic array of strings found in text

Posted on 2003-02-22
6
Medium Priority
?
464 Views
Last Modified: 2012-06-27
Hi-
I am filtering text through an array of strings.
Whenever there is a match, the matching word is set with bold tags.
So far so good.
Now I am trying to build a second array of the words that matched, and this is where I am failing.
Here is the script:

Dim target
target = Request.Form("target")
Dim X
Function order(ByVal strYourString)
redim X(UBound(X)+"learn Me!")
strYourString = Replace(strYourString, vbCrLf, "<BR>")
Dim arrItem(5)
Dim I
arrItem(0)  =   "hamburger"
arrItem(1)  =   "pickle"
arrItem(2)  =   "hot dog"
arrItem(3)  =   "onion"
arrItem(4)  =   "ketchup"

For Each I in arrItem
redim X(ubound(X) + I)
strYourString = Replace(strYourString,I,"<b>" & I & "</b> ")


Next    
order = strYourString
End Function

Thanks very much
Stephen
0
Comment
Question by:Stephen_NYC
5 Comments
 
LVL 2

Expert Comment

by:rbagdonas
ID: 8000882
Well first off you are not actually adding those words to the second array.  Let's debug your code.  try to comment your code more and it might help you work it out.

'run through the first array
For Each I in arrItem
  'redimension the second array (although I do not see you populating it)
  'you don't need this unless you intend to set the variable associated with it but looking at your need for just a string at the end, get rid of it
  'redim X(ubound(X) + I)
  'currently you are just resetting this variable everytime
  'here is your old code  
  'strYourString = Replace(strYourString,I,"<b>" & I & "</b> ")
  'here is what you might be thinking - actually build a long string by concatenating the results
  strYourString = strYourString & Replace(strYourString,I,"<b>" & I & "</b> ")
   
Next    


Try that.  Comment, comment, comment for downstream developers.

R
0
 

Author Comment

by:Stephen_NYC
ID: 8001103
thanks very much for your help.
sorry about the lack of comments
I should heven clearer: I am trying to make the matching words bold within the artticle AND create a seperate wordlist.

I re-commented the code and tried to include your suggestion but get this error:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'ubound'
here's the code:
<%
'call the data from the form text area
Dim target
target = Request.Form("target")
'create an array to fill with matching words
Dim X

Function order(ByVal strYourString)
'replace textarea carriage returns with HTML breaks
strYourString = Replace(strYourString, vbCrLf, "<BR>")
'set array of target words to match
Dim arrItem(3)
Dim I
arrItem(0)  =   "hamburger"
arrItem(1)  =   "pickle"
arrItem(2)  =   "hot dog"
'run through the first array
For Each I in arrItem
'set the matching words in bold WITHIN the article
     strYourString = Replace(strYourString,I,"<b><u>" & I & "</u></b>  ")
'redimension the second array with matching words for a seperate wordlist
     redim X(ubound(X) + I)

Next
     order = strYourString
     wordlist = X
End Function
%>
<HTML><BODY>
<% Response.Write wordlist %>
<% Response.Write order(target)  %>
</BODY></HTML>
0
 
LVL 28

Accepted Solution

by:
sybe earned 200 total points
ID: 8004524
Why not use the "Filter" Function.

From VBScript HelpFile:
====================================
Returns a zero-based array containing a subset of a string array based on a specified filter criteria.

Filter(InputStrings, Value[, Include[, Compare]])

InputStrings
Required. One-dimensional array of strings to be searched.

Value
Required. String to search for.

Include
Optional. Boolean value indicating whether to return substrings that include or exclude Value. If Include is True, Filter returns the subset of the array that contains Value as a substring. If Include is False, Filter returns the subset of the array that does not contain Value as a substring.

Compare
Optional. Numeric value indicating the kind of string comparison to use. See Settings section for values.


(...)

The following example uses the Filter function to return the array containing the search criteria "Mon":

Dim MyIndex
Dim MyArray (3)
MyArray(0) = "Sunday"
MyArray(1) = "Monday"
MyArray(2) = "Tuesday"
MyIndex = Filter(MyArray, "Mon") ' MyIndex(0) contains "Monday".
=========================================
0
 

Expert Comment

by:CleanupPing
ID: 9576942
Stephen_NYC:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 58

Expert Comment

by:Gary
ID: 9754298
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by sybe

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question