我在apache free marker.
中有以下情况
str1= Shruti
str2
可能是( "Shruti" ,"shruti", shruti,'Shruti' or SHRUTI)
如果字符串2是double quote
或single quot
e或纯文本,我们需要将其返回true。也应该不区分大小写。如果包含和比较字符串,如何忽略字符串中的单引号和双引号?
基本上,我想比较2个字符串。如果包含“单引号或双引号”,则应忽略。我尝试使用str1=str2?remove_beginning(""")?remove_end(""")
,但显示错误。
replace()
并通过用反斜杠\"
和\'
转义引号来匹配引号。我还使用trim()
删除前导和尾随空格,并使用lower_case()
忽略大小写。我在Online FreeMarker Tester中尝试了以下内容str1 = "\"Hi\""
str2 = "'hi'"
<#if str1?trim?replace("\'","")?replace("\"","")?lower_case == str2?trim?replace("\'","")?replace("\"","")?lower_case>
The two strings are equal
${str1?trim?replace("\'","")?replace("\"","")?lower_case} = ${str2?trim?replace("\'","")?replace("\"","")?lower_case}
</#if>
两个字符串相等hi =嗨
这里是可用于比较两个字符串的函数。
<#function is_equal x y> <#return x?trim?replace("\'","")?replace("\"","")?lower_case == y?trim?replace("\'","")?replace("\"","")?lower_case> </#function> <#if is_equal(str1,str2)> The two strings are equal </#if>