1

I trying to find out if one string contains another. But, unfortunately, fn:contains function is case-sensitive. Are there are any ways to make it case-insensitive?

I tried to put both into one case:

fn:contains(car.color.toLowerCase(), smartBean.txt.toLowerCase()) ? 'true' : 'false'

But it didn't work due to method's brackets. I also can't use f:to-upper inside f:contains function.

TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
Don_Quijote
  • 936
  • 3
  • 18
  • 27

2 Answers2

2

There's a fn:containsIgnoreCase(). Just use it instead.

#{fn:containsIgnoreCase(car.color, smartBean.txt)}

By the way, your failed toLowerCase() attempt should have been done as follows:

#{fn:contains(fn:toLowerCase(car.color), fn:toLowerCase(smartBean.txt))}

Using toUpperCase() works as good as well:

#{fn:contains(fn:toUpperCase(car.color), fn:toUpperCase(smartBean.txt))}

Perhaps you just made an EL syntax error.

Note that the ? 'true' : 'false' part is completely superfluous as that's already returned by the function.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

For those just finding this, @BalusC's answer is correct - but structure has changed, see just fn:upper-case, fn:lower-case - don't see the ignoreCase option anymore but if you cast it one way or the other to compare, it will work.

Kari
  • 121
  • 1
  • 5