?
Solved

a dynamic array of strings found in text

Posted on 2003-02-22
6
Medium Priority
?
457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

801 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