To compare two strings that should be identical match:
mystringa=”deedubs”
mystringb=”Dee Dubs”
TestComp = StrComp(mystringa, mystringb) If TestComp <> 0 Then Response.Write("The strings don't match") End If
ASP Classic and VBScript tips, tuts links and snips This seems to be a sick way to code arrays in asp from a string
Here is a vbscript reference pdf.
Are you trying to break a string up into smaller pieces? ASP provides an easy to use split function which lets you dice and slice a string.
Let’s say you take in a sentence and want to put each word into a different variable. So you take in
NameStr = “Mr. John Smith”
Set up the array to hold the results with
Dim WordArray
then do the split, using a space as the split indicator
WordArray = Split(NameStr, ” “)
Now WordArray(0) is equal to “Mr.”, WordArray(1) is equal to “John” and WordArray(2) is equal to “Smith”! You can use various array functions and other string functions to work with these results.
Best practices Redirect a user to a location.
While I could response.write a javascript relocation, this is not best practice for security and performance, we would want to execute this code on the server side, so that it can’t be manipulated in any way by a malicious user.
<script>document.location=”myfile.asp”</script> — this is handled on the client machine after they have recieved the page. This could be messed with by a hacker, and I am not even going to give you any reasons why or how.
newUri = “http://www.mysite.com/myspecialpage.html”
Response.Redirect(newUri)
The only drawback is that this can’t be used after any content has been written to the page. Here is a great article from microsoft about the variables and how to use them.
Check if a string has letters in it.
A basic validation to see if a string doesnt have letters in it:
Set re =New RegExp
re.Pattern ="[a-z]"
re.IgnoreCase =True
re.Global =True
hasMatches = re.Test("12345abc")
If hasMatches =True
'it has letters in it.
End If