如何检查字符串是否以特定子字符串结尾?

发布于 2024-10-07 17:30:45 字数 63 浏览 0 评论 0原文

是否有冷融合字符串函数来检查一个字符串是否以另一个字符串结尾?如果没有,实现这一目标最简单、最有效的方法是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

静谧 2024-10-14 17:30:45

您可以使用 right(string, numberofcharacters) 函数。

示例(cf脚本):

existingString = "The Quick brown Fox jumps";
tailString = "umps";
stringMatch = false;
if (right(existingString, len(tailString)) eq tailString){
   stringMatch = true;
}

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;
}
℉服软 2024-10-14 17:30:45

这是我快速跳到 java 级别的地方。

string = "This is my fancy string";

<cfoutput>#string.endsWith("string")#</cfoutput>

这应该输出 TRUE

这里有更多详细信息:
http:// download.oracle.com/javase/6/docs/api/java/lang/String.html#endsWith(java.lang.String)

请注意,endsWith() 区分大小写。

要解决这个问题,请使用 LCase() 或 UCase(),例如

Ucase(string).endsWith("STRING");

也应该返回 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

一袭白衣梦中忆 2024-10-14 17:30:45

我找到的解决方案( http://tutorial130.easycfm.com/ ) -
使用正则表达式 find - REFindNoCase,并用 $ 符号表示字符串的结尾。

REFindNoCase("end$", "check if this string ends with end")

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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文