[thelist] Regular Expression

Eric Vitiello evolt at perceive.net
Thu Mar 7 08:47:00 CST 2002


-- Feingold Josh S [Thu, 7 Mar 2002 09:36:21 -0500]:
>I am programming in an ASP environment and want to use a regular
>expression to find out if a string is the only thing in another string.  Can
>anyone help me?
>
>Specifically, if I had the string "CATS,DOGS,RATS"  I would like to
>test if the string only says "CATS."


I usually choose regular expressions, but this is not something that you need the fat regular expression parser for.

try this:

Function isOnlyString(original, test)
	If (InStr(original, test)) Then
		' the test string is in the original
		If (Len(test) = Len(original)) Then
			' the lengths of the strings are the same,
			' therefore, the test string is the only thing in the string.
			isOnlyString = True
		Else
			isOnlyString = False
		End If
	Else
		isOnlyString = False
	End If
End Function


This function will look in the original string for the test string.  if it's in there, then it checks to see if the two strings are of the same length.  If they are, then the test string is the only thing in the original string.

simple, eh?

---
Eric Vitiello
Perceive Designs
<www.perceive.net>




More information about the thelist mailing list