473,320 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to search a string

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
Feb 6 '06 #1
3 1270
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.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 6 '06 #2
"diablo" <di****@noplace.com> wrote in message
news:CT******************@newsfe5-win.ntli.net...
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
%>
Feb 6 '06 #3
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:we********************@comcast.com...
"diablo" <di****@noplace.com> wrote in message
news:CT******************@newsfe5-win.ntli.net...
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
%>


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

I tested it as a VBS file using WScript.Echo not Response.Write.
Feb 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
4
by: Ken Fine | last post by:
I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string, return the highlighted search term along with the...
22
by: Phlip | last post by:
C++ers: Here's an open ended STL question. What's the smarmiest most templated way to use <string>, <algorithms> etc. to turn this: " able search baker search charlie " into this: " able...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
0
by: Hriday | last post by:
Hi there, I am working on a web application in ASP.NET My web server and AD machine are in the same domain but located on diffrent phisical machine, I am not able to search user's info by the...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
4
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.