2010-12-16 134 views

回答

12

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

示例(CFSCRIPT):

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

谢谢!这看起来像一个很好的解决方案......我想我会坚持我的,因为我正在寻找的子字符串是一对字母字符的组合......但感谢您的回应! – froadie 2010-12-16 09:11:01

+1

@froadie你的字符串将永远是几个字母字符的组合......直到它不是。为什么在有更清晰,更安全,更好的解决方案时留下潜在的问题?不要欺骗。 – jfrobishow 2010-12-16 13:57:52

2

的溶液,我发现(http://tutorial130.easycfm.com/) - 使用一个正则表达式的发现 - REFindNoCase,具有$符号来表示字符串的结束。

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

如果您只想比较文字字符,此函数可以很好地工作。如果搜索字符串包含特殊字符并且在正则表达式中有含义,则会遇到问题。像。?$ + *。您将不得不先逃脱它们 – 2010-12-16 09:05:29

+4

这里没有必要使用正则表达式。 @Andreas Schuldhaus的解决方案更好,他解释了为什么正则表达式会引起头痛。例如:“有些人遇到问题时,会想”我知道,我会用正则表达式“,现在他们有两个问题。” http://www.codinghorror.com/blog/2008/06/regular-expressions-now-you-have-two-problems.html – orangepips 2010-12-16 11:47:24

+1

我个人比较喜欢正则表达式,但这是一个过度杀伤的例子。上面列出的left()方法更高效。 – 2010-12-16 14:59:41

10

这是我跳到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(),例如,使用LCase()或UCase()来解决这个问题。

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

也应该返回true

相关问题