• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP JSTL String Replace all ignoring case

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I have hit one of those small speed bumps in my code, so could do with a hand please. I am trying to do within a JSP using JSTL a string replace but the string compare must ignore case. For instance:

Sample input string "Hi ${Firstname}"

I want to do a replace and replace Firstname with John. But the curve ball is I am dealing with a lot of legacy records and the capitalisation of the string inside the ${...} varies greatly. So is sometimes ${firstname} and even ${firstName}. Sloppy I know but it is someone else's legacy I have to live with.

Anyway, it appears to me that the fn:replace function is only ever case sensitive with no override to make it case insensitive, is this correct?

All ideas welcome, but if possible would like to do it in a JSP.

Thanks in advance - Meanwhile I will go back to scratching my head on this.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wait a minute. You are saying that there are typos in the scoped variable names that you are trying to fix with an EL function? Are you serious?

You don't fix typos in code with more code. You fix the code.

Or has your issue been misunderstood?
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. Backing away from the example: no, there is no case-insensitive variant of the JSTL's replace function. It's pretty easy to write your own though.
 
David Cowan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Wait a minute. You are saying that there are typos in the scoped variable names that you are trying to fix with an EL function? Are you serious?

You don't fix typos in code with more code. You fix the code.

Or has your issue been misunderstood?



Sorry if it wasn't clear. They aren't scoped variables, they are just string placeholders in a string, indicating they need to be replaced with an actual value at run time.

example

Input string - "Hi ${Firstname}, thanks for your comments."

should be after replacing ${Firstname} with run time value of John.

new string - "Hi John, thanks for your comments."

It is an unfortunate choice of string replacement notation I agree with respect to confusing things with JSTL. Hope this makes more sense.

I know in Java we could use string.replaceAll, I am just very surprised that they have left out of JSTL the equivalent given how many people must actually need to do it.


 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, whew! Now I understand!

Yeah, I can see your point. On the other hand, I've been using JSTL since day 1 and never missed this functionality. They needed to draw the line somewhere, and a case-sensitive replace didn't make the cut. Of course you can "fake" one with a combination of replace() an toLowerCase(), or write your own EL function.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your best bet is to fix the inconsistencies, which should be pretty simple.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic