View Full Version : Checking if a word or a group of words exist in a variable
04-17-2006, 11:39 PM
I would like to learn if there is a function in ASP checking if a word or group of words included in a variable???
test="This is an example sentence"
I am looking for a function logic like:
if "example sentence" is in test then
04-18-2006, 04:25 PM
words = Array("red", "bat", "ball")
sentence = "Johnny is kicking a ball that is red"
For x=0 To Ubound(words)
If InStr(sentence, words(x)) Then
result = result & words(x) & ","
sentence = Replace(sentence, words(x), "<strong>" & words(x) & "</strong>")
If Len(result) > 0 Then
Response.Write "The sentence<br>""" & sentence & """<br>contains " & Left(result, Len(result)-1)
Response.Write "words not found in sentence"
04-20-2006, 01:13 AM
Thanks Degsy. Actually by saying "group of words" I meant exactly a sentence. For example:
"This is an example sentence,This is the second example sentence" is my variable value.
I want to check if exactly the "This is the second example sentence" exists in the variable value. I don't want the code catch words example or sentence and say that it exists twice in the long text.
I don't know if I could explain what I try to tell. Sorry :)
04-20-2006, 05:02 PM
MyString = "blah blah blah blah This is the second example sentence blah blah blah blah"
StringImLookingFor = "This is the second example sentence"
If InStr(MyString,StringImLookingFor ) > 0 Then
response.write "String Exists"
response.write "String not found"
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.