Is there a coldfusion string function to check if a string ends with another string? If not, what is the simplest and most efficient way to accomplish this?
You can use the right(string, numberofcharacters)
function.
example (cfscript):
existingString = "The Quick brown Fox jumps";
tailString = "umps";
stringMatch = false;
if (right(existingString, len(tailString)) eq tailString){
stringMatch = true;
}
This is where I skip down to the java level real fast.
string = "This is my fancy string";
<cfoutput>#string.endsWith("string")#</cfoutput>
This should output TRUE
More details here: http://download.oracle.com/javase/6/docs/api/java/lang/String.html#endsWith(java.lang.String)
Note that endsWith() is case sensitive.
To get around this, use LCase() or UCase(), e.g.
Ucase(string).endsWith("STRING");
Should also return TRUE
A solution that I found ( http://tutorial130.easycfm.com/ ) -
Use a regular expression find - REFindNoCase
, with a $
sign to represent the end of the string.
REFindNoCase("end$", "check if this string ends with end")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With