Whatever message this page gives is out now! Go check it out!

StringEach

Last update:
May 18, 2026

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
(Required) Closure function executed for each element in the string.
The syntax is:
callback (element, index, 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

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page