Returns the first index of an occurrence of a substring in a string from a specified starting position. Returns 0 if substring is not in string. The search is case-sensitive.
See also FindNoCase, Compare, FindOneOf, and Replace.
Find(substring, string [, start ])
String being sought.
String being searched.
Starting position for the search.
<!--- This example uses find, findnocase, and findoneof to see if a substring exists in a web page ---> <HTML> <HEAD> <TITLE> Find Example </TITLE> </HEAD> <BODY bgcolor="#FFFFD5"> <CFSET thisPath=ExpandPath("*.*")> <CFSET thisDirectory=GetDirectoryFromPath(thisPath)> <CFIF IsDefined("form.yourFile")> <CFSET yourFile=form.yourFile> <CFIF FileExists(ExpandPath(yourfile))> <P>Your file exists in this directory. You entered the correct file name, <CFOUTPUT>#GetFileFromPath("#thisPath#/#yourfile#")# </CFOUTPUT>. <CFELSE> <P>Your file was not found in this directory: <CFOUTPUT>#thisDirectory#</CFOUTPUT>. </CFIF> </CFIF> <!--- wait to have a string for searching defined ---> <CFIF IsDefined("form.myString") and IsDefined("form.type")> <!--- Now, test to see if the term was found ---> A <CFIF form.type is "find">case-sensitive <CFSET tag="find"> <CFELSEIF form.type is "findNoCase">case-insensitive <CFSET tag="findNoCase"> <CFELSEIF form.type is "findOneOf">find the first instance of any character <CFSET tag="findOneOf"> </CFIF> test for your string "<CFOUTPUT>#form.MyString# </CFOUTPUT>" in "<CFOUTPUT>#Form.yourFile#</CFOUTPUT>" </CFIF> <!--- depending upon the action desired, perform different function ---> <CFIF IsDefined("tag")> <CFSWITCH EXPRESSION="#tag#"> <CFCASE value="find"> <CFSET TheAction=Find(form.MyString, FORM.yourFile , 1)> </CFCASE> <CFCASE value="findNoCase"> <CFSET TheAction=FindNoCase(form.MyString, FORM.yourFile, 1)> </CFCASE> <CFCASE value="findOneof"> <CFSET TheAction=FindOneOf(form.MyString, FORM.yourFile, 1)> </CFCASE> <CFDEFAULTCASE> <CFSET TheAction=Find(form.MyString, FORM.YourFile, 1)> </CFDEFAULTCASE> </CFSWITCH> <CFIF TheAction is not 0> found an instance of your string at index <CFOUTPUT>#theAction# </CFOUTPUT> <CFELSE> <P>No instance of your string was found. </CFIF> </CFIF> <H3>Find Example</H3> <P>This example uses find, findnocase and findoneof to see if a substring exists in a particular file in the directory <CFOUTPUT>#GetDirectoryFromPath(thisPath)#</CFOUTPUT>. <FORM ACTION="find.cfm" METHOD="POST"> <P>Enter the name of a file in this directory <I><FONT SIZE="-1"></P> <INPUT TYPE="Text" NAME="yourFile" VALUE="daysinyear.cfm"> <P>And a substring to search for: <BR><INPUT TYPE="Text" size=25 NAME="myString" VALUE="daysinyear"> <P>Pick a search type: <SELECT NAME="type"> <OPTION VALUE="find" SELECTED>Case-Sensitive <OPTION VALUE="findNoCase">Case-Insensitive <OPTION VALUE="findOneOf">Find first instance </SELECT> <INPUT TYPE="Submit" NAME="" VALUE="start search"> </FORM> </BODY> </HTML>