Aarrgghh!!

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.


October 25, 2006 Posted by Terrence Ryan at 1:45 AM

ColdFusion, Web Development, adobemax06,



Comments

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.


Posted by: Ben Nadel at October 25, 2006 8:13 AM

Don't forget about StringBuffers, they perform very well especially when building large strings.


Posted by: JAlpino at October 25, 2006 9:49 AM

Aarrgghh Guy! I haven't compared this method to StringBuffers yet. So much to try, so little time.




Posted by: Terrence Ryan at October 25, 2006 11:26 AM

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)


Posted by: Mark Mandel at October 25, 2006 7:32 PM

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.


Posted by: Brandon Harper at October 26, 2006 12:34 AM

Aarrgghh Guy! I subtly diagree with you, Brandon. I would say if you have to optimize string manipulation, use StringBuffers.




Posted by: Terrence Ryan at October 26, 2006 1:33 AM

Great! I only recently started using Cold Fusion, and was just doing some research on it. It's good to know that ReplaceAll(); will work.


Posted by: funny jokes man at June 28, 2008 11:56 AM

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.


Posted by: tower defense at May 9, 2009 3:58 AM

supply a wide range kinds of styles fashion jewelry wholesale siver jewelry Costume jewelry


Posted by: 925 silver jewerly at May 23, 2009 4:16 AM

i didn't know that. java is running on virtual machine and coldfusion is running under java. no wonder why application gets memory leak and sets jrun.exe to over 400kb.


Posted by: bugzlife at July 22, 2009 10:31 AM

To get know more about Festival is different, some students should buy">http://www.gogetessays.com">buy an essay uk at the writing services.


Posted by: Anonymous User at July 27, 2009 7:44 AM

Coldfusion freebies create a better environment without destroying java.


Posted by: uk freebies at October 9, 2009 7:15 AM

why would anyone program in Cold Fusion? What could the possible advantage be over PHP?


Posted by: Matt at October 12, 2009 8:26 PM

Posted by Who at September 2, 2010 2:28 PM

Post a comment











Remember personal info?