FindOneOf

Return the first index of the occurrence of any character from set in string. Returns 0 if no characters are found. The search is case-sensitive.

See also Find and Compare functions.

Syntax

FindOneOf(set, string [, start ])
set

String containing one or more characters being sought.

string

String being searched.

start

Starting position for the search.

Examples

<!--- This example uses find, findnocase, and findoneof
 to see if a substring exists in a web page --->
<HTML>
<HEAD>
<TITLE>
FindOneOf 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>FindOneOf 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="findoneof.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>