how to search a string

D

diablo

Hi

if i have a string with comma seperated words. is there a way to search
another string for words that are in it?

thanks

Kal
 
E

Evertjan.

diablo wrote on 06 feb 2006 in microsoft.public.inetserver.asp.general:
if i have a string with comma seperated words. is there a way to search
another string for words that are in it?

Split them into an array,
loop the array elements,
each searching the second string.

The script depends on what language under ASP you have in mind.

Show us the code you have come up with so far.
 
M

McKirahan

diablo said:
Hi

if i have a string with comma seperated words. is there a way to search
another string for words that are in it?

thanks

Kal

Which string does "it" refer to?

Will the following help?

<%
Option Explicit

Const string1 = "a,string,with,comma,seperated,words"
Const string2 = "This is a sentence with many words."

Dim i
Dim array1
array1 = Split(string1,",")
Dim results
results = ""
results = results & "'string1' = " & string1 & vbCrLf
results = results & "'string2' = " & string2 & vbCrLf & vbCrLf
results = results & "Words from 'string1' contained in 'string2':"
Dim regular
Set regular = New RegExp
regular.Pattern = "\w+"
regular.IgnoreCase = True
regular.Global = True
Dim matches
Set matches = regular.Execute(string2)
Dim matched
For Each matched in matches
For i = 0 To UBound(array1)
If matched = array1(i) Then
results = results & vbCrLf & vbTab & matched
End If
Next
Next
Set matches = Nothing
Set regular = Nothing

Response.Write results
%>
 
M

McKirahan

McKirahan said:
Which string does "it" refer to?

Will the following help?

<%
Option Explicit

Const string1 = "a,string,with,comma,seperated,words"
Const string2 = "This is a sentence with many words."

Dim i
Dim array1
array1 = Split(string1,",")
Dim results
results = ""
results = results & "'string1' = " & string1 & vbCrLf
results = results & "'string2' = " & string2 & vbCrLf & vbCrLf
results = results & "Words from 'string1' contained in 'string2':"
Dim regular
Set regular = New RegExp
regular.Pattern = "\w+"
regular.IgnoreCase = True
regular.Global = True
Dim matches
Set matches = regular.Execute(string2)
Dim matched
For Each matched in matches
For i = 0 To UBound(array1)
If matched = array1(i) Then
results = results & vbCrLf & vbTab & matched
End If
Next
Next
Set matches = Nothing
Set regular = Nothing

Response.Write results
%>

Each instance of "vbCrLf" should be changed to "<br>" for ASP.

I tested it as a VBS file using WScript.Echo not Response.Write.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top