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(), eg
Ucase(string).endsWith("STRING");
Should also return TRUE
我找到的解决方案( http://tutorial130.easycfm.com/ ) - 使用正则表达式find - REFindNoCase
,用$
符号表示字符串的结尾。
REFindNoCase("end$", "check if this string ends with end")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.