ColdFusion String Manipulation

I don’t know if this is new to everyone, but it was to me. Jason Delmore , the Product Manager for ColdFusion informed us of something intriguing in his Developing Hybrid Applications with ColdFusion and Java and talk today. He informed us that ColdFusion strings are an extension of the Java String class. Which means that methods of Java strings are available to ColdFusion. What does this mean? It means that this is valid code:

<cfset test_1= "A string to test" />
<cfset test_2= "A string to add on to a string to test." />
<cfset test_1 = test_1.concat(test_2) />

Not only is it more elegant of other ColdFusion string concatenation techniques, it appears to run about twice as fast.

Also any other method listed in the Java String reference will work.

7 thoughts on “ColdFusion String Manipulation

  1. Yeah that is cool. Also, perhaps my favorite Java string method for use in ColdFusion is ReplaceAll() and ReplaceFirst(). These use regular expressions and are much faster than the CF equivalents.

    Like

  2. I’ve always liked the string method .startsWith() much easier to use.

    Let’s not also forget –

    Parsed Dates are java.util.Date
    Arrays are java.util.Vector
    Structs are java.util.Hashmap
    Query results are java.sql.ResultSet

    there are lots and lots out there ;o)

    Like

  3. Yes, JAlpino is correct. If you need to do much string manipulation, use StringBuffers. Strings in Java are immutable objects, so at least one new object must be created when you “change” a String.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s