StringEach

Description

iterates over a string and runs the closure function for each element in the string.

Returns

Nothing

Category

History

ColdFusion (2021 release): Added this function.

Syntax

StringEach(String string, UDFMethod callback)

Parameters

Parameter

Description

string

(Required) The input string.

callback

(Rrequired) Closure function executed for each element in the string.

Example

<cfscript> 
    myCities="St. Petersburg" 
    callback=function(city){ 
        WriteOutput(city & "<br/>") 
    }           
    StringEach(myCities,callback) 
</cfscript>

Output

S
t
.

P
e
t
e
r
s
b
u
r
g

EXAMPLE 2

<cfscript> 
    letters = "abcd" 
    callback=function(element,index){ 
        writeOutput(#index#&":"&#element#&"<br/>") 
    } 
    StringEach(letters,callback) 
</cfscript>

OUTPUT

1:a
2:b
3:c
4:d

 Adobe

Get help faster and easier

New user?

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online