getToken
Description
Determines whether a token of the list in the delimiters parameter is present in a string.
Categories
Related
Syntax
GetToken(string, index [, delimiters ])
Attributes
| Attribute | Description | Required | Default |
|---|---|---|---|
| delimiters | A string or a variable that contains one. A delimited list of delimiters. Elements may consist of multiple characters. Default list of delimiters: space character, tab character, newline character; or their codes: "chr(32)", "chr(9)", chr(10). Default list delimiter: comma character. | ||
| index | Positive integer or a variable that contains one. The position of a token. | ||
| string | A string or a variable that contains one. String in which to search. |
Returns
The
token found at position index of the string, as a string.
If index is greater than the number of tokens in the string,
returns an empty string.
Usage
The following examples show how this function works.
Example
<h3>GetToken Example</h3>
<cfif IsDefined("FORM.yourString")>
<!--- set delimiter --->
<cfif FORM.yourDelimiter is not "">
<cfset yourDelimiter = FORM.yourDelimiter>
<cfelse>
<cfset yourDelimiter = " ">
</cfif>
<!--- check whether number of elements in list is greater than or
equal to the element sought to return --->
<cfif ListLen(FORM.yourString, yourDelimiter) GTE FORM.returnElement>
<cfoutput>
Element #FORM.ReturnElement# in #FORM.yourString#,
delimited by "#yourDelimiter#"
<br>is:#GetToken(FORM.yourString, FORM.returnElement, yourDelimiter)#
</cfoutput>
...