how to search a string

Discussion in 'ASP General' started by diablo, Feb 6, 2006.

  1. diablo

    diablo Guest

    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
    diablo, Feb 6, 2006
    #1
    1. Advertising

  2. diablo

    Evertjan. Guest

    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)
    Evertjan., Feb 6, 2006
    #2
    1. Advertising

  3. diablo

    McKirahan Guest

    "diablo" <> wrote in message
    news:CTNFf.48341$...
    > 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
    %>
    McKirahan, Feb 6, 2006
    #3
  4. diablo

    McKirahan Guest

    "McKirahan" <> wrote in message
    news:...
    > "diablo" <> wrote in message
    > news:CTNFf.48341$...
    > > 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.
    McKirahan, Feb 6, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SklNLkgu?=

    Q: search string in a string

    =?Utf-8?B?SklNLkgu?=, Mar 21, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    333
    =?Utf-8?B?SklNLkgu?=
    Mar 21, 2005
  2. Smart
    Replies:
    3
    Views:
    3,936
    Roedy Green
    Feb 1, 2006
  3. Anand Pillai

    String search vs regexp search

    Anand Pillai, Oct 12, 2003, in forum: Python
    Replies:
    10
    Views:
    570
    Anand Pillai
    Oct 15, 2003
  4. Adrian
    Replies:
    7
    Views:
    419
    Adrian
    Jul 12, 2007
  5. Abby Lee
    Replies:
    5
    Views:
    368
    Abby Lee
    Aug 2, 2004
Loading...

Share This Page