Hidden String Functionality

You can do more with ColdFusion strings than you might realize by using the java.lang.String methods. Most of the functionality provided by java.lang.String is already available in some form or another as ColdFusion string functions, and of course, there’s a way to do just about anything you want with ColdFusion string functions, but there a few of nice java.lang.String methods which I really like being able to use in ColdFusion:

  • toCharArray()
  • endsWith()
  • startsWith()
  • getBytes()
  • lastIndexOf()

Just use them as though they were native (which I guess technically they are), like so:

str = "This is my string.";
myCharArray = str.toCharArray();
thisIsTrue = str.startsWith("T");
thisIsFalse = str.endsWith("!");
myByteArray = str.getBytes();
fourteen = str.lastIndexOf("i");