Click to See Complete Forum and Search --> : Javascript search()


Termite
08-13-2003, 11:43 AM
I need to find the position or existence of a "." in a string.

I believe the "." is a special character, therefore how would I search for a "." in my string.

strFileName = new String(UploadForm.FileName.value)
regExp = ".";
strExt = new String(Right(strFileName, 4))
result = strExt.search(regExp)
alert(strExt)
alert(result)

Note: The right(str, n) uses a function that mimics the behaviour of the same vbscript function.

AdamGundry
08-13-2003, 11:47 AM
You can use indexOf (http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/string.html#1196895) instead, I believe:

result = strExt.indexOf('.');

Adam

pyro
08-13-2003, 11:52 AM
Originally posted by Termite
I believe the "." is a special character, therefore how would I search for a "." in my string.Use the escape character, a backslash ( \ ) or Adam's method.